Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\events\core.c Create Date:2022-07-28 13:34:27
Last Modify:2022-05-20 07:50:19 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Returns a matching context with refcount and pincount.

Proto:static struct perf_event_context *find_get_context(struct pmu *pmu, struct task_struct *task, struct perf_event *event)

Type:struct perf_event_context

Parameter:

TypeParameterName
struct pmu *pmu
struct task_struct *task
struct perf_event *event
4269  struct perf_event_context * ctx, * clone_ctx = NULL
4271  void * task_ctx_data = NULL
4274  cpu = cpu
4276  If Not task Then
4278  err = perf_allow_cpu( & attr)
4279  If err Then Return ERR_PTR(err)
4282  cpuctx = per_cpu_ptr(pmu_cpu_context, cpu)
4283  ctx = ctx
4284  get_ctx(ctx)
4285  ++pin_count
4287  Return ctx
4290  err = -EINVAL
4291  ctxn = task_ctx_nr
4292  If ctxn < 0 Then Go to errout
4295  If attach_state & PERF_ATTACH_TASK_DATA Then
4296  task_ctx_data = 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).
4297  If Not task_ctx_data Then
4298  err = -ENOMEM
4299  Go to errout
4303  retry :
4304  ctx = Get the perf_event_context for a task and lock it.* This has to cope with with the fact that until it is locked,* the context could get moved to another task.
4305  If ctx Then
4306  clone_ctx = This must be done under the ctx->lock, such as to serialize against* context_equiv(), therefore we cannot call put_ctx() since that might end up* calling scheduler related locks and ctx->lock nests inside those.
4307  ++pin_count
4309  If task_ctx_data && Not pmu specific data Then
4311  task_ctx_data = NULL
4313  raw_spin_unlock_irqrestore( & Protect the states of the events in the list,* nr_active, and the list:, flags)
4315  If clone_ctx Then put_ctx(clone_ctx)
4317  Else
4318  ctx = alloc_perf_context(pmu, task)
4319  err = -ENOMEM
4320  If Not ctx Then Go to errout
4323  If task_ctx_data Then
4325  task_ctx_data = NULL
4328  err = 0
4329  mutex_lock( & perf_event_mutex)
4334  If Per task flags (PF_*), defined further below: & Getting shut down Then err = -ESRCH
4336  Else if perf_event_ctxp[ctxn] Then err = -EAGAIN
4338  Else
4339  get_ctx(ctx)
4340  ++pin_count
4343  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
4346  put_ctx(ctx)
4348  If err == -EAGAIN Then Go to retry
4350  Go to errout
4354  kfree(task_ctx_data)
4355  Return ctx
4357  errout :
4358  kfree(task_ctx_data)
4359  Return ERR_PTR(err)
Caller
NameDescribe
perf_event_create_kernel_counterperf_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)