linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Len Brown <lenb@kernel.org>
To: Liwei Song <liwei.song@windriver.com>
Cc: Linux PM list <linux-pm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tools/power turbostat: call pread64 in kernel directly
Date: Fri, 21 Aug 2020 14:50:04 -0400	[thread overview]
Message-ID: <CAJvTdKms0Qj3d+g_tK8oboMXebYgnPm51EdSL_UvLdw3GV6A3A@mail.gmail.com> (raw)
In-Reply-To: <52f16995-6d2d-fa7d-ed5e-682db3461d03@windriver.com>

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 <liwei.song@windriver.com> 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 <liwei.song@windriver.com> 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 <liwei.song@windriver.com>
> >> ---
> >>  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 <sys/capability.h>
> >>  #include <errno.h>
> >>  #include <math.h>
> >> +#include <sys/syscall.h>
> >>
> >>  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

  reply	other threads:[~2020-08-21 18:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  6:08 [PATCH] tools/power turbostat: call pread64 in kernel directly Liwei Song
2020-08-13 21:43 ` Len Brown
2020-08-14  2:17   ` Liwei Song
2020-08-21 18:50     ` Len Brown [this message]
2020-08-23 20:54       ` Alexander Monakov
2020-08-24  4:08         ` Liwei Song
2020-09-03 17:36           ` Len Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJvTdKms0Qj3d+g_tK8oboMXebYgnPm51EdSL_UvLdw3GV6A3A@mail.gmail.com \
    --to=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=liwei.song@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).