bpf_load_tp_prog.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <linux/bpf.h>
  17. #include <stdbool.h>
  18. #include <stdint.h>
  19. #include <bpf_helpers.h>
  20. /* Assume max of 1024 CPUs */
  21. DEFINE_BPF_MAP(cpu_pid_map, ARRAY, int, uint32_t, 1024)
  22. struct switch_args {
  23. unsigned long long ignore;
  24. char prev_comm[16];
  25. int prev_pid;
  26. int prev_prio;
  27. long long prev_state;
  28. char next_comm[16];
  29. int next_pid;
  30. int next_prio;
  31. };
  32. SEC("tracepoint/sched/sched_switch")
  33. int tp_sched_switch(struct switch_args* args) {
  34. int key;
  35. uint32_t val;
  36. key = bpf_get_smp_processor_id();
  37. val = args->next_pid;
  38. bpf_cpu_pid_map_update_elem(&key, &val, BPF_ANY);
  39. return 0;
  40. }
  41. char _license[] SEC("license") = "GPL";