Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp468073pxa; Fri, 21 Aug 2020 11:53:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwQYeaK4FGE0WxfXvd8DNOeXVc684W2tEaciYYOfK7cI5jm963GlsiHZCiSqxG1e9ib/jY X-Received: by 2002:a05:6402:2038:: with SMTP id ay24mr4402041edb.200.1598036009114; Fri, 21 Aug 2020 11:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598036009; cv=none; d=google.com; s=arc-20160816; b=jnovDKRdcDGPW/ng/BXJZxB+lFqUu7e5Du/4D1SB6q2627uiXgJrE2/fG6/yoE+xx0 uiXcWQaqfzKb3+gxEZs76fv+SfwOCy9oeUwGQXQ5A602u3ftyYdS3WQdM+h0HyyjSTrl 4e3eh0KPUkmLXgRmQtjPL6SplZ8j9ApuB6/VJj+YKaZ4wWGSK+84FbWCC8JdNBSvqbnD OnrN/mR6pC7ag4kPIZ6+Ge/J1l8qCTKK24PqiboAlflkdt6eRzPiRmOOaZO1vabjgUpe Lfxu3yYlp+mdMaCcLGOx+KZ/bUK7eiyKNYPt29tFtz6NLtXz0HVTUihezdE9sgfF3/gw c76Q== 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 :in-reply-to:references:mime-version; bh=sYzLZgwpvbGKths6LYp8+ddZvzUQfeDT+gGev5xd+mQ=; b=xXHPiQZCtUGumfreaH1mMIFFkJH2nafnFDAKzNfRdMaFJoVoqwQb7mwo/fSk+6eu0P dzslMw6H5mXZWI8+SwdkZGA01Y1WE3X6867/O8MGrIMqcfLC3+iu7ZKj56AyJzqvLiPI K+lP1K4mL0WDPX1yJu4+S6uccXj4Y4Kmxl1T9Bgd/B/vcvJvHEMRb1LycGOazxottpNJ 2roIT5DuQdd7CrEp1HUYZn3LoP5Q43sS2fIb02JLsFpTq86oT/DcYbHCsm7fRO2hKXiS sJZkWwZLdMYak9PYe4nhYn+46DddAxL6mF0VRn8pnHW1nxkP3EHaMmQt7qU0lmfbhgec tinQ== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n27si1753428eji.463.2020.08.21.11.53.05; Fri, 21 Aug 2020 11:53:29 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbgHUSuT (ORCPT + 99 others); Fri, 21 Aug 2020 14:50:19 -0400 Received: from mail-ej1-f67.google.com ([209.85.218.67]:33914 "EHLO mail-ej1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgHUSuS (ORCPT ); Fri, 21 Aug 2020 14:50:18 -0400 Received: by mail-ej1-f67.google.com with SMTP id o23so3526321ejr.1; Fri, 21 Aug 2020 11:50:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sYzLZgwpvbGKths6LYp8+ddZvzUQfeDT+gGev5xd+mQ=; b=uANUCq4AkqWLkoH2FU99OPkqwdK+63+Q+fuAQiZtQj6PdoZpe2WIL2I8kN5ZossFXX 1ojLCVg6HqESB0klZGeNRh1RolTaEKgTZFfQ4M3O2OyqC7mw4v6/UFrmXKtPtR60Tf4S j3Ry+IMl6hzhPmx1YcIVNrgAuse6sDUNrwnN/V9YhznzRup0373t3M3gMZYmilUmcHyR N7jN2DHAYx/pgJo23rP9lrW8Vl/IqZjwMMY+dmRS/9hpRnNlngKPnwU06DyLGnzj/xFz IhPOyFITZJqD9JHrB5dHkpXo3QAmsGablkAzarrDhflfhhVn6wfRc8t4gjqoxqEKITQu AaZg== X-Gm-Message-State: AOAM532DwVbC/H4P7zXTr3jPX4mq9QvjjWSrwUby5CoPEnts52PjAetf 6ARLXzzAuEwgJmm31cH5/VKxxLaGvZ+fkIsq7wUW82fPtIY= X-Received: by 2002:a17:906:b157:: with SMTP id bt23mr4451828ejb.354.1598035815823; Fri, 21 Aug 2020 11:50:15 -0700 (PDT) MIME-Version: 1.0 References: <20200717060849.12469-1-liwei.song@windriver.com> <52f16995-6d2d-fa7d-ed5e-682db3461d03@windriver.com> In-Reply-To: <52f16995-6d2d-fa7d-ed5e-682db3461d03@windriver.com> From: Len Brown Date: Fri, 21 Aug 2020 14:50:04 -0400 Message-ID: Subject: Re: [PATCH] tools/power turbostat: call pread64 in kernel directly To: Liwei Song Cc: Linux PM list , Linux Kernel Mailing List 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 Re: offset size The offsets on this file are the MSR offsets. What MSR are you trying to access at offset 0xc0010299? Re: pread vs pread64 If I take on faith that you have some kind of 32-bit execution environment that makes pread into pread32 instead of pread64, and that truncates an off_t to 32-bits from 64-bits, and it actually makes sense to request a read at this large offset... would we really have to invoke syscall() directly -- couldn't we invoke pread64() directly? (eg. below) thanks, -Len @@ -490,11 +491,12 @@ int get_msr_fd(int cpu) return fd; } -int get_msr(int cpu, off_t offset, unsigned long long *msr) +int get_msr(int cpu, unsigned long long offset, unsigned long long *msr) { ssize_t retval; - retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); + retval = pread64(get_msr_fd(cpu), msr, sizeof(*msr), offset); if (retval != sizeof *msr) err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); On Thu, Aug 13, 2020 at 10:17 PM Liwei Song wrote: > > with multilib lib32 support, the rootfs will be 32-bit, > the kernel is still 64-bit, in this case run turbostat > will failed with "out of range" error. > > Thanks, > Liwei. > > On 8/14/20 05:43, Len Brown wrote: > > Huh? > > > > On Fri, Jul 17, 2020 at 2:09 AM Liwei Song wrote: > >> > >> with 32-bit rootfs, the offset may out of range when set it > >> to 0xc0010299, define it as "unsigned long long" type and > >> call pread64 directly in kernel. > >> > >> Signed-off-by: Liwei Song > >> --- > >> tools/power/x86/turbostat/turbostat.c | 5 +++-- > >> 1 file changed, 3 insertions(+), 2 deletions(-) > >> > >> diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c > >> index 33b370865d16..4c5cdfcb5721 100644 > >> --- a/tools/power/x86/turbostat/turbostat.c > >> +++ b/tools/power/x86/turbostat/turbostat.c > >> @@ -33,6 +33,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> > >> char *proc_stat = "/proc/stat"; > >> FILE *outf; > >> @@ -381,11 +382,11 @@ int get_msr_fd(int cpu) > >> return fd; > >> } > >> > >> -int get_msr(int cpu, off_t offset, unsigned long long *msr) > >> +int get_msr(int cpu, unsigned long long offset, unsigned long long *msr) > >> { > >> ssize_t retval; > >> > >> - retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); > >> + retval = syscall(SYS_pread64, get_msr_fd(cpu), msr, sizeof(*msr), offset); > >> > >> if (retval != sizeof *msr) > >> err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); > >> -- > >> 2.17.1 > >> > > > > -- Len Brown, Intel Open Source Technology Center