Function report |
Source Code:kernel\events\core.c |
Create Date:2022-07-28 13:40:44 |
| Last Modify:2022-05-20 07:50:19 | Copyright©Brick |
| home page | Tree |
| Annotation kernel can get tool activity | Download SCCT | Chinese |
Name:Allocate and initialize an event structure
Proto:static struct perf_event *perf_event_alloc(struct perf_event_attr *attr, int cpu, struct task_struct *task, struct perf_event *group_leader, struct perf_event *parent_event, perf_overflow_handler_t overflow_handler, void *context, int cgroup_fd)
Type:struct perf_event
Parameter:
| Type | Parameter | Name |
|---|---|---|
| struct perf_event_attr * | attr | |
| int | cpu | |
| struct task_struct * | task | |
| struct perf_event * | group_leader | |
| struct perf_event * | parent_event | |
| perf_overflow_handler_t | overflow_handler | |
| void * | context | |
| int | cgroup_fd |
| 10685 | If cpu >= Setup number of possible processor ids Then |
| 10690 | event = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc). |
| 10698 | If Not group_leader Then group_leader = event |
| 10701 | mutex_init - initialize the mutex*@mutex: the mutex to be initialized* Initialize the mutex to unlocked state.* It is not allowed to initialize an already locked mutex.( & child_mutex) |
| 10702 | Initialization list head |
| 10704 | Initialization list head |
| 10705 | Initialization list head |
| 10706 | Initialization list head |
| 10708 | Initialization list head |
| 10709 | Initialization list head |
| 10710 | Initialization list head |
| 10711 | INIT_HLIST_NODE( & hlist_entry) |
| 10714 | init_waitqueue_head( & waitq) |
| 10715 | pending_disable = -1 |
| 10716 | init_irq_work( & pending, perf_pending_event) |
| 10718 | mutex_init - initialize the mutex*@mutex: the mutex to be initialized* Initialize the mutex to unlocked state.* It is not allowed to initialize an already locked mutex.( & mmap_mutex) |
| 10719 | raw_spin_lock_init( & lock) |
| 10721 | atomic_long_set( & refcount, 1) |
| 10724 | group_leader = group_leader |
| 10725 | pmu = NULL |
| 10726 | oncpu = -1 |
| 10728 | parent = parent_event |
| 10730 | ns = get_pid_ns(task_active_pid_ns(current process)) |
| 10731 | id = atomic64_inc_return( & perf_event_id) |
| 10733 | state = PERF_EVENT_STATE_INACTIVE |
| 10735 | If task Then |
| 10736 | attach_state = PERF_ATTACH_TASK |
| 10742 | target = get_task_struct(task) |
| 10745 | clock = local_clock |
| 10746 | If parent_event Then clock = clock |
| 10749 | If Not overflow_handler && parent_event Then |
| 10750 | overflow_handler = overflow_handler |
| 10751 | context = overflow_handler_context |
| 10764 | If overflow_handler Then |
| 10765 | overflow_handler = overflow_handler |
| 10766 | overflow_handler_context = context |
| 10767 | Else if is_write_backward(event) Then |
| 10769 | overflow_handler_context = NULL |
| 10770 | Else |
| 10772 | overflow_handler_context = NULL |
| 10777 | pmu = NULL |
| 10780 | sample_period = sample_period |
| 10781 | If use freq, not period && sample_freq Then sample_period = 1 |
| 10783 | last_period = sample_period |
| 10785 | local64_set( & period_left, sample_period) |
| 10791 | If children inherit it && sample_type & PERF_SAMPLE_READ Then Go to err_ns |
| 10794 | If Not has_branch_stack(event) Then branch_sample_type = 0 |
| 10797 | If cgroup_fd != -1 Then |
| 10798 | err = perf_cgroup_connect(cgroup_fd, event, attr, group_leader) |
| 10803 | pmu = perf_init_event(event) |
| 10813 | If task_ctx_nr == perf_invalid_context && cgroup_fd != -1 Then |
| 10818 | If aux_output && Not (various common per-pmu feature flags & PERF_PMU_CAP_AUX_OUTPUT) Then |
| 10820 | err = -EOPNOTSUPP |
| 10821 | Go to err_pmu |
| 10824 | err = The following implement mutual exclusion of events on "exclusive" pmus* (PERF_PMU_CAP_EXCLUSIVE) |
| 10828 | If has_addr_filter(event) Then |
| 10829 | addr_filter_ranges = kcalloc - allocate memory for an array. The memory is set to zero.*@n: number of elements.*@size: element size.*@flags: the type of memory to allocate (see kmalloc). |
| 10832 | If Not addr_filter_ranges Then |
| 10834 | Go to err_per_task |
| 10841 | If parent Then |
| 10842 | ifh = perf_event_addr_filters(event) |
| 10844 | raw_spin_lock_irq( & lock) |
| 10845 | No 3D Now!(addr_filter_ranges, addr_filter_ranges, umber of address filters this PMU can do * sizeof(structperf_addr_filter_range)) |
| 10848 | raw_spin_unlock_irq( & lock) |
| 10852 | addr_filters_gen = 1 |
| 10855 | If Not parent Then |
| 10856 | If sample_type & PERF_SAMPLE_CALLCHAIN Then |
| 10857 | err = get_callchain_buffers(sample_max_stack) |
| 10858 | If err Then Go to err_addr_filters |
| 10863 | err = security_perf_event_alloc(event) |
| 10864 | If err Then Go to err_callchain_buffer |
| 10868 | account_event(event) |
| 10870 | Return event |
| 10872 | err_callchain_buffer : |
| 10873 | If Not parent Then |
| 10874 | If sample_type & PERF_SAMPLE_CALLCHAIN Then put_callchain_buffers() |
| 10877 | err_addr_filters : |
| 10878 | kfree(addr_filter_ranges) |
| 10880 | err_per_task : |
| 10881 | exclusive_event_destroy(event) |
| 10883 | err_pmu : |
| 10886 | module_put(module) |
| 10887 | err_ns : |
| 10888 | If is_cgroup_event(event) Then perf_detach_cgroup(event) |
| 10890 | If ns Then put_pid_ns(ns) |
| 10892 | If target Then put_task_struct(target) |
| Name | Describe |
|---|---|
| perf_event_create_kernel_counter | perf_event_create_kernel_counter*@attr: attributes of the counter to create*@cpu: cpu in which the counter is bound*@task: task to profile (NULL for percpu) |
| inherit_event | Inherit an event from parent task to child task.* Returns:* - valid pointer on success* - NULL for orphaned events* - IS_ERR() on error |
| Source code conversion tool public plug-in interface | X |
|---|---|
| Support c/c++/esqlc/java Oracle/Informix/Mysql Plug-in can realize: logical Report Code generation and batch code conversion |