@@ -68,32 +68,54 @@ int main(int argc, char *argv[])
68
68
};
69
69
long ret ;
70
70
unsigned long long samples ;
71
- unsigned long long native , filtered ;
71
+ unsigned long long native , filter1 , filter2 ;
72
72
73
73
if (argc > 1 )
74
74
samples = strtoull (argv [1 ], NULL , 0 );
75
75
else
76
76
samples = calibrate ();
77
77
78
+ printf ("Current BPF sysctl settings:\n" );
79
+ system ("sysctl net.core.bpf_jit_enable" );
80
+ system ("sysctl net.core.bpf_jit_harden" );
78
81
printf ("Benchmarking %llu samples...\n" , samples );
79
82
83
+ /* Native call */
80
84
native = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
81
85
printf ("getpid native: %llu ns\n" , native );
82
86
83
87
ret = prctl (PR_SET_NO_NEW_PRIVS , 1 , 0 , 0 , 0 );
84
88
assert (ret == 0 );
85
89
90
+ /* One filter */
86
91
ret = prctl (PR_SET_SECCOMP , SECCOMP_MODE_FILTER , & prog );
87
92
assert (ret == 0 );
88
93
89
- filtered = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
90
- printf ("getpid RET_ALLOW: %llu ns\n" , filtered );
94
+ filter1 = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
95
+ printf ("getpid RET_ALLOW 1 filter : %llu ns\n" , filter1 );
91
96
92
- printf ( "Estimated seccomp overhead per syscall: %llu ns\n" ,
93
- filtered - native );
97
+ if ( filter1 == native )
98
+ printf ( "No overhead measured!? Try running again with more samples.\n" );
94
99
95
- if (filtered == native )
96
- printf ("Trying running again with more samples.\n" );
100
+ /* Two filters */
101
+ ret = prctl (PR_SET_SECCOMP , SECCOMP_MODE_FILTER , & prog );
102
+ assert (ret == 0 );
103
+
104
+ filter2 = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
105
+ printf ("getpid RET_ALLOW 2 filters: %llu ns\n" , filter2 );
106
+
107
+ /* Calculations */
108
+ printf ("Estimated total seccomp overhead for 1 filter: %llu ns\n" ,
109
+ filter1 - native );
110
+
111
+ printf ("Estimated total seccomp overhead for 2 filters: %llu ns\n" ,
112
+ filter2 - native );
113
+
114
+ printf ("Estimated seccomp per-filter overhead: %llu ns\n" ,
115
+ filter2 - filter1 );
116
+
117
+ printf ("Estimated seccomp entry overhead: %llu ns\n" ,
118
+ filter1 - native - (filter2 - filter1 ));
97
119
98
120
return 0 ;
99
121
}
0 commit comments