From a20fae808a3c979d446167d130cc05c4ed5fdee3 Mon Sep 17 00:00:00 2001 From: John Ousterhout Date: Thu, 5 Dec 2024 21:08:02 -0800 Subject: [PATCH] Change trigger lines for strip.py * Use '#ifndef __STRIP__' instead of '#if 1' * Use '#ifdef __STRIP__' instead of '#if 0' --- homa.h | 2 +- homa_impl.h | 8 ++++---- homa_incoming.c | 10 +++++----- homa_offload.c | 2 +- homa_outgoing.c | 16 ++++++++-------- homa_plumbing.c | 8 ++++---- homa_pool.h | 2 +- homa_rpc.c | 2 +- homa_sock.c | 2 +- homa_timer.c | 2 +- util/strip.py | 23 ++++++++++++----------- 11 files changed, 39 insertions(+), 38 deletions(-) diff --git a/homa.h b/homa.h index 8391141..cc89017 100644 --- a/homa.h +++ b/homa.h @@ -188,7 +188,7 @@ struct homa_rcvbuf_args { #define HOMAIOCABORT _IOWR(0x89, 0xe3, struct homa_abort_args) #define HOMAIOCFREEZE _IO(0x89, 0xef) -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ int homa_abort(int sockfd, uint64_t id, int error); int homa_send(int sockfd, const void *message_buf, size_t length, const struct sockaddr *dest_addr, diff --git a/homa_impl.h b/homa_impl.h index 83bce28..34ffde2 100644 --- a/homa_impl.h +++ b/homa_impl.h @@ -43,7 +43,7 @@ #include #include -#if 1 /* See strip.py --alt */ +#ifndef __STRIP__ /* See strip.py --alt */ #include #include "homa.h" #else /* See strip.py */ @@ -124,7 +124,7 @@ void *mock_vmalloc(size_t size); #define per_cpu(name, core) (name[core]) #endif /* __UNIT_TEST__ */ -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ /* Null out things that confuse VSCode Intellisense */ #ifdef __VSCODE__ #define raw_smp_processor_id() 1 @@ -139,7 +139,7 @@ struct homa_peer; struct homa_sock; struct homa; -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ #include "timetrace.h" #endif /* See strip.py */ #include "homa_metrics.h" @@ -1048,7 +1048,7 @@ static inline bool is_homa_pkt(struct sk_buff *skb) (tcp_hdr(skb)->urg_ptr == htons(HOMA_TCP_URGENT)))); } -#if 1 /* See strip.py --alt */ +#ifndef __STRIP__ /* See strip.py --alt */ /** * tt_addr() - Given an address, return a 4-byte id that will (hopefully) * provide a unique identifier for the address in a timetrace record. diff --git a/homa_incoming.c b/homa_incoming.c index e85b257..a6b8414 100644 --- a/homa_incoming.c +++ b/homa_incoming.c @@ -227,7 +227,7 @@ int homa_copy_to_user(struct homa_rpc *rpc) #define MAX_SKBS 20 #endif /* __UNIT_TEST__ */ struct sk_buff *skbs[MAX_SKBS]; -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ int start_offset = 0; int end_offset = 0; #endif /* See strip.py */ @@ -310,7 +310,7 @@ int homa_copy_to_user(struct homa_rpc *rpc) goto free_skbs; copied += chunk_size; } -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (end_offset == 0) { start_offset = offset; } else if (end_offset != offset) { @@ -323,7 +323,7 @@ int homa_copy_to_user(struct homa_rpc *rpc) } free_skbs: -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (end_offset != 0) { tt_record3("copied out bytes %d-%d for id %d", start_offset, end_offset, rpc->id); @@ -681,7 +681,7 @@ void homa_resend_pkt(struct sk_buff *skb, struct homa_rpc *rpc, struct homa_sock *hsk) { struct resend_header *h = (struct resend_header *)skb->data; -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ const struct in6_addr saddr = skb_canonical_ipv6_saddr(skb); #endif /* See strip.py */ struct busy_header busy; @@ -823,7 +823,7 @@ void homa_need_ack_pkt(struct sk_buff *skb, struct homa_sock *hsk, */ if (rpc && (rpc->state != RPC_INCOMING || rpc->msgin.bytes_remaining)) { -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ tt_record3("NEED_ACK arrived for id %d before message received, state %d, remaining %d", rpc->id, rpc->state, rpc->msgin.bytes_remaining); homa_freeze(rpc, NEED_ACK_MISSING_DATA, diff --git a/homa_offload.c b/homa_offload.c index f8b8fa9..c824831 100644 --- a/homa_offload.c +++ b/homa_offload.c @@ -340,7 +340,7 @@ struct sk_buff *homa_gro_receive(struct list_head *held_list, INC_METRIC(gro_grant_bypasses, 1); goto bypass; } -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ } else { tt_record4("homa_gro_receive got packet from 0x%x id %llu, type 0x%x, priority %d", saddr, homa_local_id(h_new->common.sender_id), diff --git a/homa_outgoing.c b/homa_outgoing.c index f6d94f5..eadbddd 100644 --- a/homa_outgoing.c +++ b/homa_outgoing.c @@ -358,7 +358,7 @@ int homa_xmit_control(enum homa_packet_type type, void *contents, int __homa_xmit_control(void *contents, size_t length, struct homa_peer *peer, struct homa_sock *hsk) { -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ struct netdev_queue *txq; #endif /* See strip.py */ struct common_header *h; @@ -406,7 +406,7 @@ int __homa_xmit_control(void *contents, size_t length, struct homa_peer *peer, * a bogus "reference count"). */ if (refcount_read(&skb->users) > 1) { -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (hsk->inet.sk.sk_family == AF_INET6) { pr_notice("ip6_xmit didn't free Homa control packet (type %d) after error %d\n", h->type, result); @@ -426,7 +426,7 @@ int __homa_xmit_control(void *contents, size_t length, struct homa_peer *peer, #endif /* See strip.py */ } } -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ txq = netdev_get_tx_queue(skb->dev, skb->queue_mapping); if (netif_tx_queue_stopped(txq)) tt_record4("__homa_xmit_control found stopped txq for id %d, qid %d, num_queued %d, limit %d", @@ -491,7 +491,7 @@ void homa_xmit_data(struct homa_rpc *rpc, bool force) __acquires(rpc->bucket_lock) { struct homa *homa = rpc->hsk->homa; -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ struct netdev_queue *txq; #endif /* See strip.py */ @@ -530,7 +530,7 @@ void homa_xmit_data(struct homa_rpc *rpc, bool force) homa_rpc_unlock(rpc); skb_get(skb); __homa_xmit_data(skb, rpc, priority); -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ txq = netdev_get_tx_queue(skb->dev, skb->queue_mapping); if (netif_tx_queue_stopped(txq)) tt_record4("homa_xmit_data found stopped txq for id %d, qid %d, num_queued %d, limit %d", @@ -555,7 +555,7 @@ void homa_xmit_data(struct homa_rpc *rpc, bool force) */ void __homa_xmit_data(struct sk_buff *skb, struct homa_rpc *rpc, int priority) { -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ struct homa_skb_info *homa_info = homa_get_skb_info(skb); #endif /* See strip.py */ struct dst_entry *dst; @@ -762,7 +762,7 @@ int homa_check_nic_queue(struct homa *homa, struct sk_buff *skb, bool force) return 0; if (!list_empty(&homa->throttled_rpcs)) INC_METRIC(pacer_bytes, bytes); -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (idle < clock) { if (homa->pacer_wake_time) { __u64 lost = (homa->pacer_wake_time > idle) @@ -815,7 +815,7 @@ int homa_pacer_main(void *transport) * incoming packets from being handled). */ set_current_state(TASK_INTERRUPTIBLE); -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (list_first_or_null_rcu(&homa->throttled_rpcs, struct homa_rpc, throttled_links) == NULL) tt_record("pacer sleeping"); diff --git a/homa_plumbing.c b/homa_plumbing.c index 7d330cc..03db800 100644 --- a/homa_plumbing.c +++ b/homa_plumbing.c @@ -606,7 +606,7 @@ int __init homa_load(void) } homa_gro_hook_tcp(); -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ tt_init("timetrace", homa->temp); #endif /* See strip.py */ @@ -645,7 +645,7 @@ void __exit homa_unload(void) pr_notice("Homa module unloading\n"); exiting = true; -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ tt_destroy(); #endif /* See strip.py */ @@ -1255,7 +1255,7 @@ int homa_softirq(struct sk_buff *skb) packets = skb; prev_link = &packets; for (skb = packets; skb; skb = next) { -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ const struct in6_addr saddr = skb_canonical_ipv6_saddr(skb); #endif /* See strip.py */ @@ -1567,7 +1567,7 @@ int homa_dointvec(const struct ctl_table *table, int write, if (action == 2) { homa_rpc_log_active(homa, 0); } else if (action == 3) { -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ tt_record("Freezing because of sysctl"); tt_freeze(); #endif /* See strip.py */ diff --git a/homa_pool.h b/homa_pool.h index 5596703..35aa052 100644 --- a/homa_pool.h +++ b/homa_pool.h @@ -86,7 +86,7 @@ struct homa_pool_core { }; }; -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ _Static_assert(sizeof(struct homa_pool_core) == L1_CACHE_BYTES, "homa_pool_core overflowed a cache line"); #endif /* See strip.py */ diff --git a/homa_rpc.c b/homa_rpc.c index 939e8da..d52db34 100644 --- a/homa_rpc.c +++ b/homa_rpc.c @@ -602,7 +602,7 @@ void homa_rpc_log_active(struct homa *homa, uint64_t id) */ void homa_rpc_log_tt(struct homa_rpc *rpc) { -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (rpc->state == RPC_INCOMING) { int received = rpc->msgin.length - rpc->msgin.bytes_remaining; diff --git a/homa_sock.c b/homa_sock.c index 47b58f9..3cde648 100644 --- a/homa_sock.c +++ b/homa_sock.c @@ -266,7 +266,7 @@ void homa_sock_shutdown(struct homa_sock *hsk) while (!list_empty(&hsk->dead_rpcs)) { homa_rpc_reap(hsk, 1000); i++; -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (i == 5) { tt_record("Freezing because reap seems hung"); tt_freeze(); diff --git a/homa_timer.c b/homa_timer.c index 0033921..41966f4 100644 --- a/homa_timer.c +++ b/homa_timer.c @@ -118,7 +118,7 @@ void homa_check_rpc(struct homa_rpc *rpc) } resend.priority = homa->num_priorities - 1; homa_xmit_control(RESEND, &resend, sizeof(resend), rpc); -#if 1 /* See strip.py */ +#ifndef __STRIP__ /* See strip.py */ if (homa_is_client(rpc->id)) { us = "client"; them = "server"; diff --git a/util/strip.py b/util/strip.py index 185ab9a..30f637b 100755 --- a/util/strip.py +++ b/util/strip.py @@ -18,26 +18,26 @@ #if statments in the following ways: * This entire block will be removed in the stripped version: - #if 1 /* See strip.py */ + #ifndef __STRIP__ /* See strip.py */ ... #endif /* See strip.py */ * The #if and #endif statements will be removed, leaving just the code in between: - #if 0 /* See strip.py */ + #ifdef __STRIP__ /* See strip.py */ ... #endif /* See strip.py */ * Everything will be removed except the code between #else and #endif: - #if 1 /* See strip.py */ + #ifndef __STRIP__ /* See strip.py */ ... #else /* See strip.py */ ... #endif /* See strip.py */ * It is also possible to strip using "alt" mode, with lines like this: - #if 1 /* See strip.py --alt */ - #if 0 /* See strip.py --alt */ + #ifndef __STRIP__ /* See strip.py --alt */ + #ifdef __STRIP__ /* See strip.py --alt */ If the --alt option was not specified then these lines are handled as if "--alt" wasn't present in the comments. However, if the --alt option was specified then these lines are ignored. @@ -132,8 +132,9 @@ def scan(file, alt_mode): skip_statement = False # Values of 0 or 1 mean we're in the middle of a group of lines labeled - # with '#if /* GitHubOnly */'. 0 means we're including lines, 1 means - # we're stripping them. None means we're not in such a group. + # with '#ifndef __STRIP__' or "#ifdef __STRIP__". 0 means we're including + # lines, 1 means we're stripping them. None means we're not in such a + # group. in_labeled_skip = None # Used to strip out unit testing code. Value is one of: @@ -217,16 +218,16 @@ def scan(file, alt_mode): continue if in_labeled_skip == 1: continue - if line.startswith('#if 1 /* See strip.py */') or ( - line.startswith('#if 1 /* See strip.py --alt */') + if line.startswith('#ifndef __STRIP__ /* See strip.py */') or ( + line.startswith('#ifndef __STRIP__ /* See strip.py --alt */') and not alt_mode): if slines[-1].strip() == '': delete_empty_line = True in_labeled_skip = 1 check_braces = False continue - if line.startswith('#if 0 /* See strip.py */')or ( - line.startswith('#if 0 /* See strip.py --alt */') + if line.startswith('#ifdef __STRIP__ /* See strip.py */') or ( + line.startswith('#ifdef __STRIP__ /* See strip.py --alt */') and not alt_mode): if slines[-1].strip() == '': slines.pop()