diff options
author | Paul Moore <pmoore@redhat.com> | 2013-04-19 16:13:42 -0400 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2013-04-19 16:13:42 -0400 |
commit | 208772e98813a589cf0326e00d10ab48517858dc (patch) | |
tree | 3b46db1d08e14fccb49214afcc07bf6ccfcc1450 | |
parent | b29fcac12735967f594223389cd06e41d3d07b48 (diff) | |
download | libseccomp-208772e98813a589cf0326e00d10ab48517858dc.tar.gz |
all: improved structure ordering/alignment
Shuffle some structure fields to improve packing and cacheline ordering.
Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r-- | src/db.h | 9 | ||||
-rw-r--r-- | src/gen_bpf.c | 33 | ||||
-rw-r--r-- | src/gen_bpf.h | 2 |
3 files changed, 22 insertions, 22 deletions
@@ -32,12 +32,12 @@ /* XXX - need to provide doxygen comments for the types here */ struct db_api_arg { - bool valid; - unsigned int arg; unsigned int op; scmp_datum_t mask; scmp_datum_t datum; + + bool valid; }; struct db_arg_chain_tree { @@ -54,8 +54,8 @@ struct db_arg_chain_tree { /* actions */ bool act_t_flg; - uint32_t act_t; bool act_f_flg; + uint32_t act_t; uint32_t act_f; /* list of nodes on this level */ @@ -97,7 +97,6 @@ struct db_arg_chain_tree { struct db_sys_list { /* native syscall number */ unsigned int num; - bool valid; /* priority - higher is better */ unsigned int priority; @@ -112,6 +111,8 @@ struct db_sys_list { struct db_sys_list *next; /* temporary use only by the BPF generator */ struct db_sys_list *pri_prv, *pri_nxt; + + bool valid; }; struct db_filter_attr { diff --git a/src/gen_bpf.c b/src/gen_bpf.c index d16b331..f491217 100644 --- a/src/gen_bpf.c +++ b/src/gen_bpf.c @@ -55,7 +55,6 @@ enum bpf_jump_type { }; struct bpf_jump { - enum bpf_jump_type type; union { uint8_t imm_j; uint32_t imm_k; @@ -64,21 +63,22 @@ struct bpf_jump { struct bpf_blk *blk; unsigned int nxt; } tgt; + enum bpf_jump_type type; }; #define _BPF_JMP_NO \ - ((struct bpf_jump) { TGT_NONE }) + ((struct bpf_jump) { .type = TGT_NONE }) #define _BPF_JMP_NXT(x) \ - ((struct bpf_jump) { TGT_NXT, { .nxt = (x) } }) /* be careful! */ + ((struct bpf_jump) { .type = TGT_NXT, .tgt = { .nxt = (x) } }) #define _BPF_JMP_IMM(x) \ - ((struct bpf_jump) { TGT_IMM, { .imm_j = (x) } }) + ((struct bpf_jump) { .type = TGT_IMM, .tgt = { .imm_j = (x) } }) #define _BPF_JMP_DB(x) \ - ((struct bpf_jump) { TGT_PTR_DB, { .db = (x) } }) + ((struct bpf_jump) { .type = TGT_PTR_DB, .tgt = { .db = (x) } }) #define _BPF_JMP_BLK(x) \ - ((struct bpf_jump) { TGT_PTR_BLK, { .blk = (x) } }) + ((struct bpf_jump) { .type = TGT_PTR_BLK, .tgt = { .blk = (x) } }) #define _BPF_JMP_HSH(x) \ - ((struct bpf_jump) { TGT_PTR_HSH, { .hash = (x) } }) + ((struct bpf_jump) { .type = TGT_PTR_HSH, .tgt = { .hash = (x) } }) #define _BPF_K(x) \ - ((struct bpf_jump) { TGT_K, { .imm_k = (x) } }) + ((struct bpf_jump) { .type = TGT_K, .tgt = { .imm_k = (x) } }) #define _BPF_JMP_MAX 255 #define _BPF_JMP_MAX_RET 255 @@ -99,35 +99,37 @@ struct bpf_blk { /* priority - higher is better */ unsigned int priority; - /* original db_arg_chain_tree node */ - const struct db_arg_chain_tree *node; - /* status flags */ bool flag_hash; /* added to the hash table */ bool flag_dup; /* duplicate block and in use */ bool flag_unique; /* ->blks is unique to this block */ + /* original db_arg_chain_tree node */ + const struct db_arg_chain_tree *node; + /* used during block assembly */ - struct acc_state acc_state; uint64_t hash; struct bpf_blk *hash_nxt; struct bpf_blk *prev, *next; struct bpf_blk *lvl_prv, *lvl_nxt; + struct acc_state acc_state; }; #define _BLK_MSZE(x) \ ((x)->blk_cnt * sizeof(*((x)->blks))) struct bpf_hash_bkt { struct bpf_blk *blk; - unsigned int found; - struct bpf_hash_bkt *next; + unsigned int found; }; #define _BPF_HASH_BITS 8 #define _BPF_HASH_SIZE (1 << _BPF_HASH_BITS) #define _BPF_HASH_MASK (_BPF_HASH_BITS - 1) struct bpf_state { + /* block hash table */ + struct bpf_hash_bkt *htbl[_BPF_HASH_SIZE]; + /* filter attributes */ const struct db_filter_attr *attr; /* default action */ @@ -136,9 +138,6 @@ struct bpf_state { /* target arch - NOTE: be careful, temporary use only! */ const struct arch_def *arch; - /* block hash table */ - struct bpf_hash_bkt *htbl[_BPF_HASH_SIZE]; - /* bpf program */ struct bpf_program *bpf; }; diff --git a/src/gen_bpf.h b/src/gen_bpf.h index 43f337e..954ce7f 100644 --- a/src/gen_bpf.h +++ b/src/gen_bpf.h @@ -29,8 +29,8 @@ #include "system.h" struct bpf_program { - uint16_t blk_cnt; bpf_instr_raw *blks; + uint16_t blk_cnt; }; #define BPF_PGM_SIZE(x) \ ((x)->blk_cnt * sizeof(*((x)->blks))) |