mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liwei Song <liwei.song@windriver.com>
To: Alexander Monakov <amonakov@ispras.ru>, Len Brown <lenb@kernel.org>
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: Mon, 24 Aug 2020 12:08:52 +0800	[thread overview]
Message-ID: <cce63c40-1633-5b86-6aaf-7f9a93c63eac@windriver.com> (raw)
In-Reply-To: <alpine.LNX.2.20.13.2008232345570.12553@monopod.intra.ispras.ru>



On 8/24/20 04:54, Alexander Monakov wrote:
> Hi,
> 
> I am not the original submitter, but I have answers and a proper patch :)
> 
> On Fri, 21 Aug 2020, Len Brown wrote:
> 
>> Re: offset size
>>
>> The offsets on this file are the MSR offsets.
>> What MSR are you trying to access at offset 0xc0010299?
> 
> This MSR is particular is part of AMD RAPL (energy measurements) interface.
> 
>> 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...
> 
> The problem here stems from the backward compatibility in Glibc: off_t is
> 32-bit on 32-bit x86, unless compiled with -D_FILE_OFFSET_BITS=64. This
> macro should be used for all new code. Distros should enable it for all
> builds, but when one builds turbostat 'by hand', they hit the issue.
> 
>> would we really have to invoke syscall() directly -- couldn't we
>> invoke pread64() directly? (eg. below)
> 
> No, the proper fix is to pass -D_FILE_OFFSET_BITS=64 to the compiler.
> 
> Here's the patch:

This path works with my case.

Thanks,
Liwei.


> 
> ---8<---
> 
> From: Alexander Monakov <amonakov@ispras.ru>
> Date: Sun, 23 Aug 2020 23:27:02 +0300
> Subject: [PATCH] turbostat: build with _FILE_OFFSET_BITS=64
> 
> For compatibility reasons, Glibc off_t is a 32-bit type on 32-bit x86
> unless _FILE_OFFSET_BITS=64 is defined. Add this define, as otherwise
> reading MSRs with index 0x80000000 and above attempts a pread with a
> negative offset, which fails.
> 
> Signed-off-by: Alexander Monakov <amonakov@ispras.ru>
> ---
>  tools/power/x86/turbostat/Makefile | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/power/x86/turbostat/Makefile b/tools/power/x86/turbostat/Makefile
> index 2b6551269e43..40ae44402eec 100644
> --- a/tools/power/x86/turbostat/Makefile
> +++ b/tools/power/x86/turbostat/Makefile
> @@ -12,6 +12,7 @@ turbostat : turbostat.c
>  override CFLAGS +=	-O2 -Wall -I../../../include
>  override CFLAGS +=	-DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"'
>  override CFLAGS +=	-DINTEL_FAMILY_HEADER='"../../../../arch/x86/include/asm/intel-family.h"'
> +override CFLAGS +=	-D_FILE_OFFSET_BITS=64
>  override CFLAGS +=	-D_FORTIFY_SOURCE=2
>  
>  %: %.c
> 

  reply	other threads:[~2020-08-24  4:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  6:08 Liwei Song
2020-08-13 21:43 ` Len Brown
2020-08-14  2:17   ` Liwei Song
2020-08-21 18:50     ` Len Brown
2020-08-23 20:54       ` Alexander Monakov
2020-08-24  4:08         ` Liwei Song [this message]
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=cce63c40-1633-5b86-6aaf-7f9a93c63eac@windriver.com \
    --to=liwei.song@windriver.com \
    --cc=amonakov@ispras.ru \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®