From patchwork Mon Dec 14 16:42:14 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: 11972495 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.7 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 950DBC4361B for ; Mon, 14 Dec 2020 16:43:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B0DC2246B for ; Mon, 14 Dec 2020 16:43:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406513AbgLNQnE (ORCPT ); Mon, 14 Dec 2020 11:43:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgLNQnD (ORCPT ); Mon, 14 Dec 2020 11:43:03 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5816C061793 for ; Mon, 14 Dec 2020 08:42:23 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id t22so2992781pfl.3 for ; Mon, 14 Dec 2020 08:42:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rajagiritech-edu-in.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:user-agent:mime-version; bh=JezVwkcUvzbDeHvXSRBpUCVs/qIVAUJGi+DKg0XJKa8=; b=mXy18jyh6x9Yg5x/9PYmMAfeBUgoUAzxkI+cBR3uyWjLrqttklGNM7KuVM/9iipOZe VHQ9K2I6ui+Nj3uEYv48Btuq1yNGWExK39A4eceIf3RWrY/2FfHE34g5jtEc8X1z8u2r FCxIyX3B7DGQVYCT+4BP9UO9+umtNa23eqJHtlW/q0zeoOKQ/0DxmMIvZ2fdRB8cWKAo zQRJpywYzWIU73CiY+vAFhXTp0eLd9toXWU0aoQMAVANbcruQRWN692WWd5ZsRlqIU5b r15VUxXEoJG0qsMjChSfzd0P5vjMRjzn+8aS5kXhxmo4ig7DhvGcszGEmfLFcFA9d9zv eZNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:user-agent :mime-version; bh=JezVwkcUvzbDeHvXSRBpUCVs/qIVAUJGi+DKg0XJKa8=; b=a4Fw4Zs2HTegDDCU0o1+0qiJR9O7yOlMob+JcI2XrUdYX2O3hvKiTusQnc4OgQSqKu afJ94dLJwc/lqnU+DbJOMV6iQ1wWZeCXP10YMSnTYWpRTkTzGr6MP3UiIEjz025C6TU1 isDGSgFX8HAbffhNVT+WQGAaqwFPlfPKXWzoW60Wq9pnDSSatfnQB1UoXl9stzipKw+3 fOf9Xjzbq0Cfqjgo1YO7rcSANslEmrQ4/QOGrqqhhPSyeot0rblKhD2xjL6X4HfoZefs IyOikq9V0QFmmVtWIctS9AL4031zg/wcnPFsqqd9cwNGwIl3kc1/Zv3sRsX3Ro0YPLd7 lV7g== X-Gm-Message-State: AOAM533nLa4l9cIMlAaAREQQ5fT1TfVoPI2ZIunzfan4EkMNdtXEC8Te J8uXyhTpCGvt2w2ol/8Cn6RcgbJykt3oeg== X-Google-Smtp-Source: ABdhPJzM/uVhPAKhk3NynN9yUtwSZCsn+2/4gY8gnVryTIoG815YrBdV7grCk4Reut9MNSIKbdcOIg== X-Received: by 2002:a62:3582:0:b029:19e:4935:bea2 with SMTP id c124-20020a6235820000b029019e4935bea2mr24381264pfa.34.1607964143127; Mon, 14 Dec 2020 08:42:23 -0800 (PST) Received: from [192.168.1.9] ([171.61.231.84]) by smtp.gmail.com with ESMTPSA id u12sm19496373pfn.88.2020.12.14.08.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Dec 2020 08:42:22 -0800 (PST) Message-ID: Subject: related to fixing depreciated api From: Jeffrin Jose T To: Shuah Khan Cc: "open list:KERNEL SELFTEST FRAMEWORK" , lkml Date: Mon, 14 Dec 2020 22:12:14 +0530 User-Agent: Evolution 3.38.1-2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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. 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; }