lkml.org 
[lkml]   [2010]   [Jan]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 09/12] perf/core, x86: use test_and_set_bit() to when grabbing a counter
    Date
    Using test_and_set_bit() in the generic counter allocator makes this
    atomic. Otherwise a counter could have been allocated twice.

    Signed-off-by: Robert Richter <robert.richter@amd.com>
    ---
    arch/x86/kernel/cpu/perf_event.c | 8 ++++++--
    1 files changed, 6 insertions(+), 2 deletions(-)

    diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
    index 4eb0355..3f81f91 100644
    --- a/arch/x86/kernel/cpu/perf_event.c
    +++ b/arch/x86/kernel/cpu/perf_event.c
    @@ -1395,8 +1395,13 @@ gen_get_event_idx(struct cpu_hw_events *cpuc, struct hw_perf_event *hwc)
    {
    int idx;

    +again:
    idx = find_first_zero_bit(cpuc->used_mask, x86_pmu.num_counters);
    - return idx == x86_pmu.num_counters ? -1 : idx;
    + if (idx == x86_pmu.num_counters)
    + return -1;
    + if (test_and_set_bit(idx, cpuc->used_mask))
    + goto again;
    + return idx;
    }

    /*
    @@ -1465,7 +1470,6 @@ try_generic:
    if (idx == -1)
    return -EAGAIN;

    - set_bit(idx, cpuc->used_mask);
    hwc->idx = idx;
    }
    hwc->config_base = x86_pmu.eventsel;
    --
    1.6.6



    \
     
     \ /
      Last update: 2010-01-22 15:59    [W:0.024 / U:63.556 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site