test_run.c (aaccf3c97418f169afdbb5855e9cbcbda34e90fd) | test_run.c (8bad74f9840f87661f20ced3dc80c84ab4fd55a1) |
---|---|
1/* Copyright (c) 2017 Facebook 2 * 3 * This program is free software; you can redistribute it and/or 4 * modify it under the terms of version 2 of the GNU General Public 5 * License as published by the Free Software Foundation. 6 */ 7#include <linux/bpf.h> 8#include <linux/slab.h> 9#include <linux/vmalloc.h> 10#include <linux/etherdevice.h> 11#include <linux/filter.h> 12#include <linux/sched/signal.h> 13 14static __always_inline u32 bpf_test_run_one(struct bpf_prog *prog, void *ctx, | 1/* Copyright (c) 2017 Facebook 2 * 3 * This program is free software; you can redistribute it and/or 4 * modify it under the terms of version 2 of the GNU General Public 5 * License as published by the Free Software Foundation. 6 */ 7#include <linux/bpf.h> 8#include <linux/slab.h> 9#include <linux/vmalloc.h> 10#include <linux/etherdevice.h> 11#include <linux/filter.h> 12#include <linux/sched/signal.h> 13 14static __always_inline u32 bpf_test_run_one(struct bpf_prog *prog, void *ctx, |
15 struct bpf_cgroup_storage *storage) | 15 struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) |
16{ 17 u32 ret; 18 19 preempt_disable(); 20 rcu_read_lock(); 21 bpf_cgroup_storage_set(storage); 22 ret = BPF_PROG_RUN(prog, ctx); 23 rcu_read_unlock(); 24 preempt_enable(); 25 26 return ret; 27} 28 29static u32 bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat, u32 *time) 30{ | 16{ 17 u32 ret; 18 19 preempt_disable(); 20 rcu_read_lock(); 21 bpf_cgroup_storage_set(storage); 22 ret = BPF_PROG_RUN(prog, ctx); 23 rcu_read_unlock(); 24 preempt_enable(); 25 26 return ret; 27} 28 29static u32 bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat, u32 *time) 30{ |
31 struct bpf_cgroup_storage *storage = NULL; | 31 struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = { 0 }; 32 enum bpf_cgroup_storage_type stype; |
32 u64 time_start, time_spent = 0; 33 u32 ret = 0, i; 34 | 33 u64 time_start, time_spent = 0; 34 u32 ret = 0, i; 35 |
35 storage = bpf_cgroup_storage_alloc(prog); 36 if (IS_ERR(storage)) 37 return PTR_ERR(storage); | 36 for_each_cgroup_storage_type(stype) { 37 storage[stype] = bpf_cgroup_storage_alloc(prog, stype); 38 if (IS_ERR(storage[stype])) { 39 storage[stype] = NULL; 40 for_each_cgroup_storage_type(stype) 41 bpf_cgroup_storage_free(storage[stype]); 42 return -ENOMEM; 43 } 44 } |
38 39 if (!repeat) 40 repeat = 1; 41 time_start = ktime_get_ns(); 42 for (i = 0; i < repeat; i++) { 43 ret = bpf_test_run_one(prog, ctx, storage); 44 if (need_resched()) { 45 if (signal_pending(current)) 46 break; 47 time_spent += ktime_get_ns() - time_start; 48 cond_resched(); 49 time_start = ktime_get_ns(); 50 } 51 } 52 time_spent += ktime_get_ns() - time_start; 53 do_div(time_spent, repeat); 54 *time = time_spent > U32_MAX ? U32_MAX : (u32)time_spent; 55 | 45 46 if (!repeat) 47 repeat = 1; 48 time_start = ktime_get_ns(); 49 for (i = 0; i < repeat; i++) { 50 ret = bpf_test_run_one(prog, ctx, storage); 51 if (need_resched()) { 52 if (signal_pending(current)) 53 break; 54 time_spent += ktime_get_ns() - time_start; 55 cond_resched(); 56 time_start = ktime_get_ns(); 57 } 58 } 59 time_spent += ktime_get_ns() - time_start; 60 do_div(time_spent, repeat); 61 *time = time_spent > U32_MAX ? U32_MAX : (u32)time_spent; 62 |
56 bpf_cgroup_storage_free(storage); | 63 for_each_cgroup_storage_type(stype) 64 bpf_cgroup_storage_free(storage[stype]); |
57 58 return ret; 59} 60 61static int bpf_test_finish(const union bpf_attr *kattr, 62 union bpf_attr __user *uattr, const void *data, 63 u32 size, u32 retval, u32 duration) 64{ --- 135 unchanged lines hidden --- | 65 66 return ret; 67} 68 69static int bpf_test_finish(const union bpf_attr *kattr, 70 union bpf_attr __user *uattr, const void *data, 71 u32 size, u32 retval, u32 duration) 72{ --- 135 unchanged lines hidden --- |