Received: by 10.223.176.46 with SMTP id f43csp3331753wra; Mon, 22 Jan 2018 12:15:36 -0800 (PST) X-Google-Smtp-Source: AH8x227m9vQh73pqPQPmhxOGTiYQcvLLYro+iqueVBu3OfhngPcA217nwPmZV6XcH0yujvDPrxag X-Received: by 10.36.204.85 with SMTP id x82mr7201itf.21.1516652135941; Mon, 22 Jan 2018 12:15:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516652135; cv=none; d=google.com; s=arc-20160816; b=tL6fMmv0JWkdSZgBqDI6xgSiXteV/5j1JmbERgHdy3l9RKrYYxo8duRO85u4VHpUno qqVAylGtD9L1uJR47N3nr8ySF3Zr3avSlXn+mfCHI1ly5C7nsvfBvOqmWdXyWgGtkspN aeg1dh6hMpyOAJ2YZjbXWGrIxsZTH9KE+umpLZZCA3p4VrWwGuDHBr33KtUfrLO9MnDB GGCpYFNQ5CDgP6prbmh8Omtwzvn1ZaY6wCvN5IjXpxUoqmFy9tmdUaPypkilmzuMe+ww mHaf8bc3LWIaYUFi+Tc6wxV9HPQbi/f640sgZiAxtdUPpgqD2zMCAVR9ruFew/BuarbH C6Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=F6HaihrMwUwFrWrGIvohbAXf+TJC0VvHpmtDpgI5P5w=; b=muzX0MYe9IMSd8F60wIqf3tRg99COG29f220g6tSP5DDAvmtWgCDO2+01RQvtsjz/B GIKc+yYSO0mDEr1ujTjx+ouNPF1XtoPl4msinJusYgxiPslG+WfojaAyWQGTgUq+Avmi 7AjWPQSw/c7XZZqNQXwULaOHehRkbS1EhhIK7Q7kXhbV1yQVXNxAZgwuUvc9Z7q9nFCn tFblGJKpZB0CvQG8/OiUjcbcUo2dpgex8ao6ebTuNsADRlhplBgOXyTbWXMezJN+HDO7 LjBTXt619OUS7Zec1q6EbSaC4Ac0Za9wEC1jVZXaAqx1jXrMVr0KLVsFoOBuiq0sK8To /3Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZJbO626b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r62si6645031itg.35.2018.01.22.12.15.22; Mon, 22 Jan 2018 12:15:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZJbO626b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750920AbeAVUPD (ORCPT + 99 others); Mon, 22 Jan 2018 15:15:03 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:39292 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750977AbeAVUO4 (ORCPT ); Mon, 22 Jan 2018 15:14:56 -0500 Received: by mail-wm0-f45.google.com with SMTP id b21so19308614wme.4 for ; Mon, 22 Jan 2018 12:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=F6HaihrMwUwFrWrGIvohbAXf+TJC0VvHpmtDpgI5P5w=; b=ZJbO626bMZ0EXaRiY//kkhgo4eGGHYZabAX2EajQAtsGUShh1QnDSdSFNT1doVoDxU Nhpb9yHWeKKjnWmieEQciB19OUkA9LniBwNg1kOMW056D4pqfDPpk1n8GN+Yjl38NBuv RMNT5EzhbGQl4+cI1vyd+1NiZdsWcPTn5X7WA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=F6HaihrMwUwFrWrGIvohbAXf+TJC0VvHpmtDpgI5P5w=; b=uGSNV99CILkB3Qrzc3Al9a2b3CIk8HzW60L0aOqoEb5tyBprT2WaOG6BEKx3kJ4Ynx aKHZSnuzLo9PrqUk7p7YS9Sp53hYIhbPzlf5o9m3FYbk2hM8mjFa+EM8qOnrHJGwcHH/ 0y1inUFXYpu56k1dJzX7qdMrzDMYbR0u56tmlbiqwc+1tquLn2dq/O7LpdffC58r5ZL/ 3TBdiSY5c8PshD/KU0iMsFf1S7u6hGU5+qxmNlvmRNq1zSH6+EKkoupX+l23/pTkcwMT zfgMfvxW7ERtFxitRtMo3QoV5LqhNpXIRKJQ8diiOnyiivH5cBTdGRdWqSE6X9RxZBtF C3RA== X-Gm-Message-State: AKwxytdYYzSAKBJ4ecSGOhbYAfQi48tK06q+6lv0LD7qGCDKE+kEpKFF yF/pqTP8Y3Ygot6B2/ttyV9vlejGx7u8rJ694RGG4Q== X-Received: by 10.80.217.10 with SMTP id t10mr15227092edj.171.1516652095207; Mon, 22 Jan 2018 12:14:55 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.168.164 with HTTP; Mon, 22 Jan 2018 12:14:54 -0800 (PST) In-Reply-To: <59a63753-2343-db87-c4af-5011b404a3db@arm.com> References: <1516211539-5166-1-git-send-email-mathieu.poirier@linaro.org> <1516211539-5166-8-git-send-email-mathieu.poirier@linaro.org> <59a63753-2343-db87-c4af-5011b404a3db@arm.com> From: Mathieu Poirier Date: Mon, 22 Jan 2018 13:14:54 -0700 Message-ID: Subject: Re: [PATCH v3 07/10] pert tools: Add queue management functionality To: Robert Walker Cc: Arnaldo Carvalho de Melo , Kim Phillips , Peter Zijlstra , Adrian Hunter , linux-kernel@vger.kernel.org, Alexander Shishkin , Ingo Molnar , Mike Leach , namhyung@kernel.org, suzuki.poulosi@arm.com, Jiri Olsa , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22 January 2018 at 10:25, Robert Walker wrote: > > > On 01/17/2018 05:52 PM, Mathieu Poirier wrote: >> >> Add functionatlity to setup trace queues so that traces associated with >> CoreSight auxtrace events found in the perf.data file can be classified >> properly. The decoder and memory callback associated with each queue are >> then used to decode the traces that have been assigned to that queue. >> >> Co-authored-by: Tor Jeremiassen >> Signed-off-by: Mathieu Poirier >> --- >> tools/perf/util/cs-etm.c | 208 >> ++++++++++++++++++++++++++++++++++++++++++++++- >> 1 file changed, 204 insertions(+), 4 deletions(-) >> >> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c >> index cad429ce3c00..83eb676274b5 100644 >> --- a/tools/perf/util/cs-etm.c >> +++ b/tools/perf/util/cs-etm.c >> @@ -196,15 +196,215 @@ static void cs_etm__free(struct perf_session >> *session) >> zfree(&aux); >> } >> +static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, >> + size_t size, u8 *buffer) >> +{ >> + u8 cpumode; >> + u64 offset; >> + int len; >> + struct thread *thread; >> + struct machine *machine; >> + struct addr_location al; >> + >> + if (!etmq) >> + return -1; >> + >> + machine = etmq->etm->machine; >> + if (address >= etmq->etm->kernel_start) >> + cpumode = PERF_RECORD_MISC_KERNEL; >> + else >> + cpumode = PERF_RECORD_MISC_USER; >> + >> + thread = etmq->thread; >> + if (!thread) { >> + if (cpumode != PERF_RECORD_MISC_KERNEL) >> + return -EINVAL; >> + thread = etmq->etm->unknown_thread; >> + } >> + >> + thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, >> &al); >> + >> + if (!al.map || !al.map->dso) >> + return 0; >> + >> + if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR && >> + dso__data_status_seen(al.map->dso, >> DSO_DATA_STATUS_SEEN_ITRACE)) >> + return 0; >> + >> + offset = al.map->map_ip(al.map, address); >> + >> + map__load(al.map); >> + >> + len = dso__data_read_offset(al.map->dso, machine, offset, buffer, >> size); >> + >> + if (len <= 0) >> + return 0; >> + >> + return len; >> +} >> + >> +static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace >> *etm, >> + unsigned int queue_nr) >> +{ >> + int i; >> + struct cs_etm_decoder_params d_params; >> + struct cs_etm_trace_params *t_params; >> + struct cs_etm_queue *etmq; >> + >> + etmq = zalloc(sizeof(*etmq)); >> + if (!etmq) >> + return NULL; >> + >> + etmq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE); > > > Should this and the other members of etmq alloc'd in this function be free'd > in cs_etm__free_queue() as they were in the original version at > https://github.com/Linaro/perf-opencsd/ ? I can't see them getting freed > anywhere else. Quite right - it got lost in the refactoring. Thanks for pointing this out. Mathieu > >> + if (!etmq->event_buf) >> + goto out_free; >> + >> + etmq->etm = etm; >> + etmq->queue_nr = queue_nr; >> + etmq->pid = -1; >> + etmq->tid = -1; >> + etmq->cpu = -1; >> + >> + /* Use metadata to fill in trace parameters for trace decoder */ >> + t_params = zalloc(sizeof(*t_params) * etm->num_cpu); >> + >> + if (!t_params) >> + goto out_free; >> + >> + for (i = 0; i < etm->num_cpu; i++) { >> + t_params[i].protocol = CS_ETM_PROTO_ETMV4i; >> + t_params[i].etmv4.reg_idr0 = >> etm->metadata[i][CS_ETMV4_TRCIDR0]; >> + t_params[i].etmv4.reg_idr1 = >> etm->metadata[i][CS_ETMV4_TRCIDR1]; >> + t_params[i].etmv4.reg_idr2 = >> etm->metadata[i][CS_ETMV4_TRCIDR2]; >> + t_params[i].etmv4.reg_idr8 = >> etm->metadata[i][CS_ETMV4_TRCIDR8]; >> + t_params[i].etmv4.reg_configr = >> + >> etm->metadata[i][CS_ETMV4_TRCCONFIGR]; >> + t_params[i].etmv4.reg_traceidr = >> + >> etm->metadata[i][CS_ETMV4_TRCTRACEIDR]; >> + } >> + >> + /* Set decoder parameters to simply print the trace packets */ >> + d_params.packet_printer = cs_etm__packet_dump; >> + d_params.operation = CS_ETM_OPERATION_DECODE; >> + d_params.formatted = true; >> + d_params.fsyncs = false; >> + d_params.hsyncs = false; >> + d_params.frame_aligned = true; >> + d_params.data = etmq; >> + >> + etmq->decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, >> t_params); >> + >> + zfree(&t_params); >> + >> + if (!etmq->decoder) >> + goto out_free; >> + >> + /* >> + * Register a function to handle all memory accesses required by >> + * the trace decoder library. >> + */ >> + if (cs_etm_decoder__add_mem_access_cb(etmq->decoder, >> + 0x0L, ((u64) -1L), >> + cs_etm__mem_access)) >> + goto out_free_decoder; >> + >> + etmq->offset = 0; >> + >> + return etmq; >> + >> +out_free_decoder: >> + cs_etm_decoder__free(etmq->decoder); >> +out_free: >> + zfree(&etmq->event_buf); >> + free(etmq); >> + >> + return NULL; >> +} >> + >> +static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, >> + struct auxtrace_queue *queue, >> + unsigned int queue_nr) >> +{ >> + struct cs_etm_queue *etmq = queue->priv; >> + >> + if (list_empty(&queue->head) || etmq) >> + return 0; >> + >> + etmq = cs_etm__alloc_queue(etm, queue_nr); >> + >> + if (!etmq) >> + return -ENOMEM; >> + >> + queue->priv = etmq; >> + >> + if (queue->cpu != -1) >> + etmq->cpu = queue->cpu; >> + >> + etmq->tid = queue->tid; >> + >> + return 0; >> +} >> + >> +static int cs_etm__setup_queues(struct cs_etm_auxtrace *etm) >> +{ >> + unsigned int i; >> + int ret; >> + >> + for (i = 0; i < etm->queues.nr_queues; i++) { >> + ret = cs_etm__setup_queue(etm, >> &etm->queues.queue_array[i], i); >> + if (ret) >> + return ret; >> + } >> + >> + return 0; >> +} >> + >> +static int cs_etm__update_queues(struct cs_etm_auxtrace *etm) >> +{ >> + if (etm->queues.new_data) { >> + etm->queues.new_data = false; >> + return cs_etm__setup_queues(etm); >> + } >> + >> + return 0; >> +} >> + >> static int cs_etm__process_event(struct perf_session *session, >> union perf_event *event, >> struct perf_sample *sample, >> struct perf_tool *tool) >> { >> - (void) session; >> - (void) event; >> - (void) sample; >> - (void) tool; >> + int err = 0; >> + u64 timestamp; >> + struct cs_etm_auxtrace *etm = container_of(session->auxtrace, >> + struct cs_etm_auxtrace, >> + auxtrace); >> + >> + /* Keep compiler happy */ >> + (void)event; >> + >> + if (dump_trace) >> + return 0; >> + >> + if (!tool->ordered_events) { >> + pr_err("CoreSight ETM Trace requires ordered events\n"); >> + return -EINVAL; >> + } >> + >> + if (!etm->timeless_decoding) >> + return -EINVAL; >> + >> + if (sample->time && (sample->time != (u64) -1)) >> + timestamp = sample->time; >> + else >> + timestamp = 0; >> + >> + if (timestamp || etm->timeless_decoding) { >> + err = cs_etm__update_queues(etm); >> + if (err) >> + return err; >> + } >> + >> return 0; >> } >>