Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2898444pxa; Tue, 18 Aug 2020 00:30:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYe31dJZ/fmRT9YOIRjOL+6/hoiXqz/d2+6M8QThdt+s743lnfl6sDohbOBvHBFdJa/diT X-Received: by 2002:a17:906:4d89:: with SMTP id s9mr17913995eju.365.1597735805640; Tue, 18 Aug 2020 00:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597735805; cv=none; d=google.com; s=arc-20160816; b=1GjZqdTPnIC9GwerXd/EZOx1mvnTa1YogjF+3vrG7O7iXqn+oRyY7X4UV0fa/PswsV TWrlor5938UC+5q2XoTa/9BxkFfdYHJCax/922YFGJsG5hGm3ir4XwNY5leC+gRBM5rV 6KRAj9E4nfTZcfqvpNuQCkONab4lbf0Per57hngRCtgUWteEXUVBVQ82stG0q5oUhqwf OixOPE2GIrRl5JgxOhz8/j37sNI54iO1F/IhSFyQG9ZsOYArbeC3l+KZm/6kCTyca8i/ OdLsDOicwwnhVAx9Rvu7C388bLHMcXRxqoXBTOGzkzv3GWfAaKxIzaZfLYsRQvt3zXoH nH3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=kg6Pid/S3uyECtsR9/ZQNoRBSFk6tXHhc71xqlOp1H8=; b=o+4A98is+Ixn/on5DcvxnEhrA3KjH1/D7X1pGLHUuS06DS/33fchRlFzyVETe14UOQ RzBhmw/3PW/4aSfXItVzGaI3aH/UgCL3Nbi5x4JW2GLBcEcj3vM+dskfkwDoYbIW16R6 LWeGbbBou1NqsgEMTx7ZLtaSI72XMYTvmoNTEDklr0RH/aaZeqkLzClS7wyG++WiiuAD kJwW43uAtZQy2AwgVl3o5V4IdfOJJWuxyPCPdchTcE1bdND6i7eBCy8w6CsAEbH61Urx mH14dHSmgDg44wy6KsfzH3HxfOmIvE6yrCmg6fYDf0r5sWznppZlld8XFyk8zqwfyJ7c VF5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=YTPipOkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si12840775ejr.426.2020.08.18.00.29.42; Tue, 18 Aug 2020 00:30:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=YTPipOkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726324AbgHRH2Y (ORCPT + 99 others); Tue, 18 Aug 2020 03:28:24 -0400 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:5910 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726631AbgHRH2W (ORCPT ); Tue, 18 Aug 2020 03:28:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597735702; x=1629271702; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=kg6Pid/S3uyECtsR9/ZQNoRBSFk6tXHhc71xqlOp1H8=; b=YTPipOkkR5R4LrUIt+cHb3uckw8l8V2ZMLqsHx5i1DmFXmmYtYcRvu37 Om9YqM3w0ydwPo/kXvE1ULOL1tT4jX6ajo9Dux6pP/4aWLU7Ug1D1nlD6 GU+5CmevhU1Wmf9t0TIrtC/R4+zmSKCa7BRqI13Sy2jAyootBfaO814OX U=; X-IronPort-AV: E=Sophos;i="5.76,326,1592870400"; d="scan'208";a="60596917" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 18 Aug 2020 07:28:20 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com (Postfix) with ESMTPS id 72002A18E4; Tue, 18 Aug 2020 07:28:17 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 Aug 2020 07:28:16 +0000 Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 Aug 2020 07:27:59 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v7 08/10] tools/damon/record: Support physical memory monitoring Date: Tue, 18 Aug 2020 09:24:59 +0200 Message-ID: <20200818072501.30396-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200818072501.30396-1-sjpark@amazon.com> References: <20200818072501.30396-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D38UWB002.ant.amazon.com (10.43.161.171) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park This commit allows users to record the data accesses on physical memory address space by passing 'paddr' as target to 'damo-record'. If the init regions are given, the regions will be monitored. Else, it will monitor biggest conitguous 'System RAM' region in '/proc/iomem' and monitor the region. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 2 ++ tools/damon/record.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index a22ec3777c16..6ff278117e84 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -27,6 +27,8 @@ def set_target(tid, init_regions=[]): if not os.path.exists(debugfs_init_regions): return 0 + if tid == 'paddr': + tid = 42 string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions]) return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), shell=True, executable='/bin/bash') diff --git a/tools/damon/record.py b/tools/damon/record.py index 11fd54001472..6fd0b59c73e0 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -101,6 +101,29 @@ def set_argparser(parser): parser.add_argument('-o', '--out', metavar='', type=str, default='damon.data', help='output file path') +def default_paddr_region(): + "Largest System RAM region becomes the default" + ret = [] + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) != 2: + continue + name = fields[1].strip() + if name != 'System RAM': + continue + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + + sz_region = end - start + if not ret or sz_region > (ret[1] - ret[0]): + ret = [start, end] + return ret + def main(args=None): global orig_attrs if not args: @@ -122,7 +145,11 @@ def main(args=None): target = args.target target_fields = target.split() - if not subprocess.call('which %s &> /dev/null' % target_fields[0], + if target == 'paddr': # physical memory address space + if not init_regions: + init_regions = [default_paddr_region()] + do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) + elif not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): do_record(target, True, init_regions, new_attrs, orig_attrs, pidfd) else: -- 2.17.1