Received: by 10.223.185.111 with SMTP id b44csp50849wrg; Fri, 9 Mar 2018 00:39:09 -0800 (PST) X-Google-Smtp-Source: AG47ELuYZwCMRfb/NWbfTFTPVDR64kN5yl4TNEAeAxDtTcPq/J1bUZ8u8rxJlMotZAs72yFYZQuI X-Received: by 2002:a17:902:8f8f:: with SMTP id z15-v6mr9144098plo.315.1520584749337; Fri, 09 Mar 2018 00:39:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520584749; cv=none; d=google.com; s=arc-20160816; b=t77MJDgUYvrAtzIKF7OrsN/Ewq8OSnTqCYcb0JnglGKq+cMrKDiBY8T4fyy5fujrxM UZaYRn/M7oYMkV3KW/AnAu14v1TpH8/C2zZUnPpkFcCSM0Jl5Gh/zNjDyqDH0dkUwrTB P1zllKbNytUTmQWURD6Vr0caxVvZkxXgjKdVRuFQ5pnghH8p0u2HubPvKLf1Y7albqPk y+oET7xtT/8RuRpMRnm2CfeTXZHmKzgT5e53k/6A1Mwcg6JrnRHw7C1PdwdTcn0imUUM xzn5zcfWWpcPnMrh+PKBYRcggg1jDA5256tNQNNsFa8IfAF1K13Lkgt8pq0vGv8xToep 6sXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=XU19C1UmpGanwanSH5FHXGNFI8lvsRIX7ChyrUJ8yLo=; b=lu9QG9Kp/kZkITNmOpOQ5Q8HzcUpDHnGHUqMKVn0IzslcUJ/LlLLc2ZuLf72q+wXKw qnenBDapHAz6sTAz9oeZsShPKTCjOaIHGtnHJhjMg/npOY9059JLw+yl523cgVKGCGt+ WjOxurXbjBUDcUHdHaXsll/0udLR4e8njhC7L4a4O3QFfg8M9oO0BFVIdkxpVuJ2sWYW LuiuXQd3jefrg2ZyLaQwgRSsUdmRXtNV5AolkUbslsyr6SmU2Af62fTDpzZUhcNtm8Ez GH25Y6qZ5GDuxZpKAONeZtKUjOmnXTDGTmgJdNqzazPz5KQt9NcF4Dw5cuK0ZUPsm8RQ SkZA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si422350pgf.582.2018.03.09.00.38.55; Fri, 09 Mar 2018 00:39:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752144AbeCIIhd (ORCPT + 99 others); Fri, 9 Mar 2018 03:37:33 -0500 Received: from terminus.zytor.com ([198.137.202.136]:35149 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751243AbeCIIha (ORCPT ); Fri, 9 Mar 2018 03:37:30 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w298b9mH023079; Fri, 9 Mar 2018 00:37:09 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w298b9FN023076; Fri, 9 Mar 2018 00:37:09 -0800 Date: Fri, 9 Mar 2018 00:37:09 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Changbin Du Message-ID: Cc: hpa@zytor.com, namhyung@kernel.org, acme@redhat.com, peterz@infradead.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, changbin.du@intel.com, tglx@linutronix.de, mingo@kernel.org Reply-To: acme@redhat.com, namhyung@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, peterz@infradead.org, jolsa@kernel.org, tglx@linutronix.de, mingo@kernel.org, changbin.du@intel.com In-Reply-To: <1520307457-23668-2-git-send-email-changbin.du@intel.com> References: <1520307457-23668-2-git-send-email-changbin.du@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf sched: Move thread::shortname to thread_runtime Git-Commit-ID: 8640da9f4fea88c8fbb44ff63fde4000203cb7d1 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 8640da9f4fea88c8fbb44ff63fde4000203cb7d1 Gitweb: https://git.kernel.org/tip/8640da9f4fea88c8fbb44ff63fde4000203cb7d1 Author: Changbin Du AuthorDate: Tue, 6 Mar 2018 11:37:36 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 7 Mar 2018 10:22:26 -0300 perf sched: Move thread::shortname to thread_runtime The thread::shortname only used by sched command, so move it to sched private structure. Signed-off-by: Changbin Du Acked-by: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1520307457-23668-2-git-send-email-changbin.du@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-sched.c | 95 +++++++++++++++++++++++++++------------------- tools/perf/util/thread.h | 1 - 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 83283fedb00f..0a632a6b6228 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -254,6 +254,8 @@ struct thread_runtime { u64 total_delay_time; int last_state; + + char shortname[3]; u64 migrations; }; @@ -897,6 +899,37 @@ struct sort_dimension { struct list_head list; }; +/* + * handle runtime stats saved per thread + */ +static struct thread_runtime *thread__init_runtime(struct thread *thread) +{ + struct thread_runtime *r; + + r = zalloc(sizeof(struct thread_runtime)); + if (!r) + return NULL; + + init_stats(&r->run_stats); + thread__set_priv(thread, r); + + return r; +} + +static struct thread_runtime *thread__get_runtime(struct thread *thread) +{ + struct thread_runtime *tr; + + tr = thread__priv(thread); + if (tr == NULL) { + tr = thread__init_runtime(thread); + if (tr == NULL) + pr_debug("Failed to malloc memory for runtime data.\n"); + } + + return tr; +} + static int thread_lat_cmp(struct list_head *list, struct work_atoms *l, struct work_atoms *r) { @@ -1480,6 +1513,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, { const u32 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); struct thread *sched_in; + struct thread_runtime *tr; int new_shortname; u64 timestamp0, timestamp = sample->time; s64 delta; @@ -1519,22 +1553,28 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, if (sched_in == NULL) return -1; + tr = thread__get_runtime(sched_in); + if (tr == NULL) { + thread__put(sched_in); + return -1; + } + sched->curr_thread[this_cpu] = thread__get(sched_in); printf(" "); new_shortname = 0; - if (!sched_in->shortname[0]) { + if (!tr->shortname[0]) { if (!strcmp(thread__comm_str(sched_in), "swapper")) { /* * Don't allocate a letter-number for swapper:0 * as a shortname. Instead, we use '.' for it. */ - sched_in->shortname[0] = '.'; - sched_in->shortname[1] = ' '; + tr->shortname[0] = '.'; + tr->shortname[1] = ' '; } else { - sched_in->shortname[0] = sched->next_shortname1; - sched_in->shortname[1] = sched->next_shortname2; + tr->shortname[0] = sched->next_shortname1; + tr->shortname[1] = sched->next_shortname2; if (sched->next_shortname1 < 'Z') { sched->next_shortname1++; @@ -1552,6 +1592,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, for (i = 0; i < cpus_nr; i++) { int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; struct thread *curr_thread = sched->curr_thread[cpu]; + struct thread_runtime *curr_tr; const char *pid_color = color; const char *cpu_color = color; @@ -1569,9 +1610,14 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, else color_fprintf(stdout, cpu_color, "*"); - if (sched->curr_thread[cpu]) - color_fprintf(stdout, pid_color, "%2s ", sched->curr_thread[cpu]->shortname); - else + if (sched->curr_thread[cpu]) { + curr_tr = thread__get_runtime(sched->curr_thread[cpu]); + if (curr_tr == NULL) { + thread__put(sched_in); + return -1; + } + color_fprintf(stdout, pid_color, "%2s ", curr_tr->shortname); + } else color_fprintf(stdout, color, " "); } @@ -1587,7 +1633,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, pid_color = COLOR_PIDS; color_fprintf(stdout, pid_color, "%s => %s:%d", - sched_in->shortname, thread__comm_str(sched_in), sched_in->tid); + tr->shortname, thread__comm_str(sched_in), sched_in->tid); } if (sched->map.comp && new_cpu) @@ -2200,37 +2246,6 @@ static void save_idle_callchain(struct idle_thread_runtime *itr, callchain_cursor__copy(&itr->cursor, &callchain_cursor); } -/* - * handle runtime stats saved per thread - */ -static struct thread_runtime *thread__init_runtime(struct thread *thread) -{ - struct thread_runtime *r; - - r = zalloc(sizeof(struct thread_runtime)); - if (!r) - return NULL; - - init_stats(&r->run_stats); - thread__set_priv(thread, r); - - return r; -} - -static struct thread_runtime *thread__get_runtime(struct thread *thread) -{ - struct thread_runtime *tr; - - tr = thread__priv(thread); - if (tr == NULL) { - tr = thread__init_runtime(thread); - if (tr == NULL) - pr_debug("Failed to malloc memory for runtime data.\n"); - } - - return tr; -} - static struct thread *timehist_get_thread(struct perf_sched *sched, struct perf_sample *sample, struct machine *machine, diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 40cfa36c022a..14d44c3235b8 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -26,7 +26,6 @@ struct thread { pid_t ppid; int cpu; refcount_t refcnt; - char shortname[3]; bool comm_set; int comm_len; bool dead; /* if set thread has exited */