From patchwork Tue Dec 15 13:05:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeffrin Jose T X-Patchwork-Id: 11974807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 782B2C4361B for ; Tue, 15 Dec 2020 13:06:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23E982250F for ; Tue, 15 Dec 2020 13:06:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729405AbgLONGq (ORCPT ); Tue, 15 Dec 2020 08:06:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728701AbgLONGl (ORCPT ); Tue, 15 Dec 2020 08:06:41 -0500 Received: from mail-vs1-xe43.google.com (mail-vs1-xe43.google.com [IPv6:2607:f8b0:4864:20::e43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56C5BC06179C for ; Tue, 15 Dec 2020 05:06:01 -0800 (PST) Received: by mail-vs1-xe43.google.com with SMTP id u7so10908821vsg.11 for ; Tue, 15 Dec 2020 05:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rajagiritech-edu-in.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M6JcWbpI6jGa01OPHXVMD2J1Jt7vqUJ1vGYJXmb3BYg=; b=GySPu3JPn5oY5z7HEHsmBkWTtINCkr42KRf5OqSuvPZXiIDp/6j7IIku1ErEVbzbla TO5zYrJ5XkzpcCLkXeCcTcbXnTxbbUur4fxOhLOIvmsA0qPIy3/RrNvvHREkfCMaRgtI XCgva/BiX2NszgfeuU/PudEkoE5XxRM2hnmkdGwsWBaFDPKuNnjCggRyl3WPnjL7MSCY +3x/R1vUsVoavfWw8teVdheWGKGsNZcw0FO0fxpNKKi8TCaGePbm/Wtc7FrrcXk9HYFN R+SmturpAPzB8742ZBC8IbFa4yieJ94bSrF59pQ9Uh94V0k5behe+HT2G0XgFdo7suIh qSXQ== 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=M6JcWbpI6jGa01OPHXVMD2J1Jt7vqUJ1vGYJXmb3BYg=; b=kjy86PrBW3sQRo/zzMVZCXIEVnFhVlDAO+2WsdtxxZeaTSmdWFLhYuYkTgtXHi1y5J 1b089tcr8QakRyQ9dQbRj9IVReeUIxzvdB2NpQoMZLdJ5YAfN/GfDd3eyUnqAr7rMRz6 suh/iuKIVLaqzj/aAR1RM8IogM+oZXVFpxCjoI2RTK25t7SNzutMPyXmFMUB4SLIfd7n V1aEjMrCcnqU1gLUv8L5UeEkqNd6DF3cJ6ZJnMi0i3ru5h1BYDIosNd4XlF/INte4xFj O31nBAGHR1lmjFkGC2Qix54ab4gBRw8Mr23rZT44IYIHXw0dUbj4NKqS+39Axp3VWJ0T 49EQ== X-Gm-Message-State: AOAM533P3qMp7mZRgDkdrnOWvGD5/0KMLUk9U2HCGiw810vl2KIS6XzN JA4qQ9hb6hQNI11WKNWfdc1zSjjPgTzgJ5BdTl4dc0vGnQmQNg== X-Google-Smtp-Source: ABdhPJzd2zd1mfj+2JOvG7Kb2IKM7m6kQfLvrUUQH1zRlLxKdNB34zX+2yZ2pPZSMkGbOyZpb8F0jrq3/7pDR8A/s0U= X-Received: by 2002:a05:6102:18c:: with SMTP id r12mr28967382vsq.34.1608037560466; Tue, 15 Dec 2020 05:06:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jeffrin Thalakkottoor Date: Tue, 15 Dec 2020 18:35:24 +0530 Message-ID: Subject: [WARNING ]Re: related to fixing depreciated api To: Shuah Khan Cc: "open list:KERNEL SELFTEST FRAMEWORK" , lkml Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org On Mon, Dec 14, 2020 at 10:12 PM Jeffrin Jose T wrote: > > hello, > > i have worked on to fix depreciated api issue from > tools/testing/selftests/intel_pstate/aerf.c > > i met with the following error related... > > --------------x------------------x-----------------> > $pwd > /home/jeffrin/UP/linux-kselftest/tools/testing/selftests/intel_pstate > $make > gcc -Wall -D_GNU_SOURCE aperf.c /home/jeffrin/UP/linux- > kselftest/tools/testing/selftests/kselftest_harness.h > /home/jeffrin/UP/linux-kselftest/tools/testing/selftests/kselftest.h - > lm -o /home/jeffrin/UP/linux- > kselftest/tools/testing/selftests/intel_pstate/aperf > aperf.c: In function ‘main’: > aperf.c:58:2: warning: ‘ftime’ is deprecated [-Wdeprecated- > declarations] > 58 | ftime(&before); > | ^~~~~ > In file included from aperf.c:9: > /usr/include/x86_64-linux-gnu/sys/timeb.h:39:12: note: declared here > 39 | extern int ftime (struct timeb *__timebuf) > | ^~~~~ > aperf.c:67:2: warning: ‘ftime’ is deprecated [-Wdeprecated- > declarations] > 67 | ftime(&after); > | ^~~~~ > In file included from aperf.c:9: > /usr/include/x86_64-linux-gnu/sys/timeb.h:39:12: note: declared here > 39 | extern int ftime (struct timeb *__timebuf) > | ^~~~~ > $ > ----------------x---------------x----------------------> > > > from ftime manual i found that it is depreciated... > > This function is deprecated, and will be removed in a future version > of the GNU C library. Use clock_gettime(2) instead. > > > now clock_gettime gives new data structure. > > struct timespec { > time_t tv_sec; /* seconds */ > long tv_nsec; /* nanoseconds */ > }; > > > i worked on with the new data structure and some errors that came > along. > typical final output looks good but values of runtime and typical > frequency > does not look normal during "sudo bash run.sh". > > output of "git diff" and a portion of output of "sudo bash run.sh". > is attached. > > > > -- > software engineer > rajagiri school of engineering and technology - autonomous > > diff --git a/tools/testing/selftests/intel_pstate/aperf.c b/tools/testing/selftests/intel_pstate/aperf.c index f6cd03a87493..7e35e7872f16 100644 --- a/tools/testing/selftests/intel_pstate/aperf.c +++ b/tools/testing/selftests/intel_pstate/aperf.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -22,10 +22,12 @@ int main(int argc, char **argv) { long long tsc, old_tsc, new_tsc; long long aperf, old_aperf, new_aperf; long long mperf, old_mperf, new_mperf; - struct timeb before, after; + struct timespec before, after; + clockid_t clkid; long long int start, finish, total; cpu_set_t cpuset; + if (argc != 2) { usage(argv[0]); return 1; @@ -41,6 +43,10 @@ int main(int argc, char **argv) { sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu); fd = open(msr_file_name, O_RDONLY); + #define CLOCKFD 3 + #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) + clkid = FD_TO_CLOCKID(fd); + if (fd == -1) { printf("/dev/cpu/%d/msr: %s\n", cpu, strerror(errno)); @@ -55,7 +61,7 @@ int main(int argc, char **argv) { return 1; } - ftime(&before); + clock_gettime(clkid,&before); pread(fd, &old_tsc, sizeof(old_tsc), 0x10); pread(fd, &old_aperf, sizeof(old_mperf), 0xe7); pread(fd, &old_mperf, sizeof(old_aperf), 0xe8); @@ -64,7 +70,7 @@ int main(int argc, char **argv) { sqrt(i); } - ftime(&after); + clock_gettime(clkid,&after); pread(fd, &new_tsc, sizeof(new_tsc), 0x10); pread(fd, &new_aperf, sizeof(new_mperf), 0xe7); pread(fd, &new_mperf, sizeof(new_aperf), 0xe8); @@ -73,11 +79,10 @@ int main(int argc, char **argv) { aperf = new_aperf-old_aperf; mperf = new_mperf-old_mperf; - start = before.time*1000 + before.millitm; - finish = after.time*1000 + after.millitm; - total = finish - start; - - printf("runTime: %4.2f\n", 1.0*total/1000); - printf("freq: %7.0f\n", tsc / (1.0*aperf / (1.0 * mperf)) / total); + start = before.tv_sec*1000000 + before.tv_nsec; + finish = after.tv_sec*1000000 + after.tv_nsec; + total = finish - start; + printf("runTime: %4.2f\n", 1.0*total/1000000); + printf("freq: %7.0f\n", tsc / (1.0 * aperf /1.0 * (mperf)) / total); return 0; }