Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1899233pxa; Sun, 23 Aug 2020 21:49:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtrr2Apsu0udKKkiuOXzhI1bjljTDXXg66+cWbS6TINHLAoH6B4W2K0ok9waAid3pFhtHU X-Received: by 2002:a50:aadd:: with SMTP id r29mr3703102edc.219.1598244585350; Sun, 23 Aug 2020 21:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598244585; cv=none; d=google.com; s=arc-20160816; b=NPp5jh3joKsAykKYRqzRxcYx21bTFpg54c5qSWGAOoAG4FP+PDU5Qg/+Tzmmr2BQEz 8RH4xEyGTQXOYnwy9Bo5MN/z1OHPnuO+e7WZrVlnMHPsF0VCyWMxdc99vEJcPqEs+5xg hwioCb3rZYukwAq9LJC+YY55RI7/xRpX5fa585c5lda7doDTqvY3wslJvJ71LmHeJKvW CA6rbvGjuODv0Nlmg6miMhKWk7GQxM7DPcUsk+xuD3zgsfGS8tIA9iq4Fi9ECS4w+mJ2 GrmY1CHvBb1KMKqz4sVWoFkK/wo4t8tbOLFvNy/yxozffBFOBSFXvVwhX1D4VvEx5kgL 8oqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=mMltVB5du9Lc/C4r5v7m/1/a/IOkCes4nl96Uu4qZVw=; b=Lzdh53DT0elydeAOxaLLrVIl0Pd/inwhh7TCmIPJ5AVovAKhH2VP16teF9yJ7+YwW+ Gu0OjSlt8/U3fUhY/3obse7qk1gJHhr4uXXUIrFbsfYUKoCmDPMrrjnwMWtcZJomDXU8 f5Fc/633+C2bN9ohGUm6HVwIhkWLeg6N7C/LsVe589/it5KO9eyIjsCtNHeWyWMK9CBP ZlbtXBLajdQiSVt4jNA3bHOgFlbjczD5qWUHxKbhbno+464ELcRkvRV+WrQprSd+Y+XE u5VSLEzPoM1iNriycyigtYJfzBcLvCkmdcdC7nz8kT/vHpnNmJ2l9nS5C7ufROUzAbPZ xQPw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si6009238ejh.45.2020.08.23.21.49.22; Sun, 23 Aug 2020 21:49:45 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726027AbgHXEJS (ORCPT + 99 others); Mon, 24 Aug 2020 00:09:18 -0400 Received: from mail.windriver.com ([147.11.1.11]:58956 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725271AbgHXEJQ (ORCPT ); Mon, 24 Aug 2020 00:09:16 -0400 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail.windriver.com (8.15.2/8.15.2) with ESMTPS id 07O48tMV028285 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Sun, 23 Aug 2020 21:08:55 -0700 (PDT) Received: from [128.224.162.157] (128.224.162.157) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.3.487.0; Sun, 23 Aug 2020 21:08:54 -0700 Subject: Re: [PATCH] tools/power turbostat: call pread64 in kernel directly To: Alexander Monakov , Len Brown CC: Linux PM list , Linux Kernel Mailing List References: <20200717060849.12469-1-liwei.song@windriver.com> <52f16995-6d2d-fa7d-ed5e-682db3461d03@windriver.com> From: Liwei Song Message-ID: Date: Mon, 24 Aug 2020 12:08:52 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > 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 > --- > 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 >