Skip to content

Commit

Permalink
Change trigger lines for strip.py
Browse files Browse the repository at this point in the history
* Use '#ifndef __STRIP__' instead of '#if 1'
* Use '#ifdef __STRIP__' instead of '#if 0'
  • Loading branch information
johnousterhout committed Dec 6, 2024
1 parent c2fdc6a commit a20fae8
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion homa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions homa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <net/gro.h>
#include <net/rps.h>

#if 1 /* See strip.py --alt */
#ifndef __STRIP__ /* See strip.py --alt */
#include <linux/version.h>
#include "homa.h"
#else /* See strip.py */
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions homa_incoming.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion homa_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 8 additions & 8 deletions homa_outgoing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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",
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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",
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions homa_plumbing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion homa_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion homa_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion homa_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion homa_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
23 changes: 12 additions & 11 deletions util/strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a20fae8

Please sign in to comment.