Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp667716lqt; Mon, 18 Mar 2024 22:55:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVJAhUgL1LU87pQqJuEbW2O4rMf30Z1EASUf6xeSEV7wEL4cc7PIkfEnC5Bi9JQL8wrTvoyjVYfhDQZEPPFwR/hzPpjrVCA0hlDzfqyjg== X-Google-Smtp-Source: AGHT+IF9bYuHQlG/4HrRlmomdOJJ+JIXWMNTjLTPy1ytl7QQGAWBtNWvwlr97qOTqohLhDsXUAHB X-Received: by 2002:a17:907:9710:b0:a46:a3dc:3359 with SMTP id jg16-20020a170907971000b00a46a3dc3359mr7291002ejc.46.1710827729731; Mon, 18 Mar 2024 22:55:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710827729; cv=pass; d=google.com; s=arc-20160816; b=R7DU6CzL/yVwPrCtbfHT75sMcNd2xrEVDozmLhIlPh3yZBE2Z6rqAuYb/quPeE1eFg k+VtnZYWa0k6Yqov2oZF0Xv4M9+mWGmnTO0VlhsATEKfQrtVRH0HygMHRWPlpiyXEoLF +5uhfEHEBzwQ/pIvO8bKM5vJ4pFroFSZiwOtVzD+oaZ/ikDB9bqeCgWO9sOmV1VIVDq8 dgY87eDY/voHzIIuMSzLzO+xBxbxIobCmre5k9H8Bwwc6zxm/3jZITt269Tj4w1FSopO l6V3rEaZvaRwwFpdCvjLhERrNf3T2ix5nqZq1sGI3h0waRZklCHDZf6lelzSatTwyhwV O/BA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RVPphP0N82c1J6A77HEEOJ6cMlUPAedFHFDUpLGrwHU=; fh=44lErbL5kvNUjSV6UDWgBEjJyOJpjjMpxi6K+HFi+Bc=; b=K7RU7WFaB3l5ZKknzUyKT7OBwAEnzM+xY6GKBxJNantnCSKpH1qcfMlNcKrosisKHE rAREEyKT8mVLOWoAHnx3omYjznm6dDshChuWYI+xJhA6Wc+E0oMjLoKBfD57VrzTDjWw 016dJhs0SuwOmY3B4Wif/iDBJmvIN4cVhL7miNSDo7finaTPymR/HI0yPAt/INLQAt5R GMSKQducQjT+s9sWBNai7iDS85/QJvMw5RtZEfbxfersGbTH9y63QH4hPw16qc8Nt9y9 6gyxdalgVoFt8bPs7sSNq07tHLN/QvqukN1JQht4xSpHNznA/Gq7Chd5eedvqgeTlQkw Qcmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hInb/Drm"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107043-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kt5-20020a170906aac500b00a46a13e555csi3191999ejb.838.2024.03.18.22.55.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 22:55:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hInb/Drm"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107043-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 788C71F224F0 for ; Tue, 19 Mar 2024 05:55:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 054CB80034; Tue, 19 Mar 2024 05:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hInb/Drm" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1620B7FBAF; Tue, 19 Mar 2024 05:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827488; cv=none; b=tGuQ7JLrjw+XUkwQg6kG/WFaPnbo3T/hy40h07Fzy7WMOxsVxmubh6OCjqHF6+0beQcfuKMD7CAMfo9GLdedtbUgkNgDig2AmQHQM7ELDm622E7U+ykKsMHuf+gnKBe6N3kfyoQUh0f7gUGbXbe9aBxs2NAR92iJNkiBEqyzy3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827488; c=relaxed/simple; bh=uJSdghEGLKMsHLGxhc9BRL8wS6WYTQdxoEBPQ8UAYQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GoHNcoF+GmZjO9h3Iiii7PgUqe3fWH3gykKzeZVTCFHHgFsMgG3oA6u5gB8K9BXCPHRfmFrk/Txzk4gnTgACe/BYT5qI8Ke6CqgU0PaYC+lzzgUgonF3aSVhEP9IemxYTeekYC8WuDjuYSePOWVj0qOdwzxrHrITa3KRgLlupio= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hInb/Drm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74F2AC43390; Tue, 19 Mar 2024 05:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710827487; bh=uJSdghEGLKMsHLGxhc9BRL8wS6WYTQdxoEBPQ8UAYQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hInb/DrmioxpC/1b7/UzJjjH3S6SZXRm5+NvXmMkdpP7JdiNPwPzW/CgECrt99GvY WmuldXyzJMwtk40n/QQ2ONF2418mBqW7Zw0e7oLN0rkSB254XqIlWXDm0ABEP/OKU1 6NV/YUeVNRoYlNJSYqtTMkii+8SKg338p+T2k8KZgm55W56DJdGSIfI92ByX2KowqZ M2m4bASKV0mDFFcA8HjVusbUrJ3e+Il9HH66nCq+yr0DerAksUJyT/N/NBzQqyiD6Q Jfye6q9ShAs8WdQZVBPQswKw1RpDun2pud2Maco9073Hvo9oQSfnUCZuhVWlqeExX6 7zVJjx58hK0FA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 17/23] perf annotate-data: Handle this-cpu variables in kernel Date: Mon, 18 Mar 2024 22:51:09 -0700 Message-ID: <20240319055115.4063940-18-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog In-Reply-To: <20240319055115.4063940-1-namhyung@kernel.org> References: <20240319055115.4063940-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On x86, the kernel gets the current task using the current macro like below: #define current get_current() static __always_inline struct task_struct *get_current(void) { return this_cpu_read_stable(pcpu_hot.current_task); } So it returns the current_task field of struct pcpu_hot which is the first member. On my build, it's located at 0x32940. $ nm vmlinux | grep pcpu_hot 0000000000032940 D pcpu_hot And the current macro generates the instructions like below: mov %gs:0x32940, %rcx So the %gs segment register points to the beginning of the per-cpu region of this cpu and it points the variable with a constant. Let's update the instruction location info to have a segment register and handle %gs in kernel to look up a global variable. Pretend it as a global variable by changing the register number to DWARF_REG_PC. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 21 +++++++++++++++++++-- tools/perf/util/annotate.c | 7 +++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index f5329a78a97d..d57622ddd5d3 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -790,7 +790,7 @@ static void delete_var_types(struct die_var_type *var_types) /* It's at the target address, check if it has a matching type */ static bool check_matching_type(struct type_state *state, struct data_loc_info *dloc, int reg, - Dwarf_Die *type_die) + Dwarf_Die *cu_die, Dwarf_Die *type_die) { Dwarf_Word size; u32 insn_offset = dloc->ip - dloc->ms->sym->start; @@ -864,6 +864,23 @@ static bool check_matching_type(struct type_state *state, return true; } + if (map__dso(dloc->ms->map)->kernel && arch__is(dloc->arch, "x86")) { + u64 addr; + int offset; + + if (dloc->op->segment == INSN_SEG_X86_GS && dloc->op->imm) { + pr_debug_dtp(" this-cpu var\n"); + + addr = dloc->op->offset; + + if (get_global_var_type(cu_die, dloc, dloc->ip, addr, + &offset, type_die)) { + dloc->type_offset = offset; + return true; + } + } + } + pr_debug_dtp("\n"); return false; } @@ -897,7 +914,7 @@ static bool find_data_type_insn(struct data_loc_info *dloc, int reg, if (this_ip == dloc->ip) { found = check_matching_type(&state, dloc, reg, - type_die); + cu_die, type_die); goto out; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 3aa3a3b987ad..e4121acb4f88 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -3921,6 +3921,13 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he) op_loc->offset, dl); } + /* This CPU access in kernel - pretend PC-relative addressing */ + if (map__dso(ms->map)->kernel && arch__is(arch, "x86") && + op_loc->segment == INSN_SEG_X86_GS && op_loc->imm) { + dloc.var_addr = op_loc->offset; + op_loc->reg1 = DWARF_REG_PC; + } + mem_type = find_data_type(&dloc); if (mem_type) istat->good++; -- 2.44.0.291.gc1ea87d7ee-goog