From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932790AbcKHQiq (ORCPT ); Tue, 8 Nov 2016 11:38:46 -0500 Received: from mail-dm3nam03on0077.outbound.protection.outlook.com ([104.47.41.77]:12992 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932237AbcKHQin (ORCPT ); Tue, 8 Nov 2016 11:38:43 -0500 From: Bart Van Assche To: Johannes Thumshirn , "Martin K . Petersen" , James Bottomley CC: Hannes Reinecke , Christoph Hellwig , Linux SCSI Mailinglist , Linux Kernel Mailinglist , Arnd Bergmann Subject: Re: [PATCH] libfc: fix seconds_since_last_reset miscalculation Thread-Topic: [PATCH] libfc: fix seconds_since_last_reset miscalculation Thread-Index: AQHSOZxoB4rqxR59R0+2RX5K3eLbrQ== Date: Tue, 8 Nov 2016 15:04:43 +0000 Message-ID: References: <1478594694-98847-1-git-send-email-jthumshirn@suse.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@sandisk.com; x-originating-ip: [50.152.170.61] x-ms-office365-filtering-correlation-id: f8c6487c-f797-48f8-6adc-08d407e89242 x-microsoft-exchange-diagnostics: 1;BLUPR02MB1681;7:GvKhelnZNp+LboeCIF8wItczpRUOw4YHgYyp6nxWtFb8AAWYPeDZ4mpVKBUkZkYfRewwpwSo/MvLAlnhfpNQFXJRHQrt9JkgjIg+2Z7MdzEq+sVwFyuVky7oInW3Uhvw8uPeaR3uiXiA2GpS//8ztBGuhU2EJKC8PknR9IzApYSzTC/kMYi4Z4ZvoqaZGESKwbyqTXQZQ+Otqx7VNiliis9mQBv9rDTyn7XPmXXB1EMBVylO/y1L17KEoC/wS1JoRVRxvztru+4zctteci6LhYjB/cP7OhiHTlcJNoBjf1U47wcIodA9j6LXacPc6ZiUs0ZPKc2tpcS3voc2mzTSs2B2qAChLlHqOHhTtuQg2e4=;20:8sgWkPKI1TNo7M8CGAoD0jjeojy/ra6/bLcjq452C18goj6x4T7alFt8heaqvuneLiahp0rIFL6nyzFebSbHATsT9sUOYJ2lHPMCVl0iHMYFVpvhKsBwu3RaLt8j3dQ6BcdUCHdFImci9nD+f2kR2gUBvuLRhYQodRJY/OrPXg1l6VMhNGEq0+21Z7opmmAOa7ztTg7ZS9rzGDeQvZAxvrAVaj3TqBFTFeFpK7XKF/cwKLGlkT47jfv3fQc5fkvS x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB1681; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026);SRVR:BLUPR02MB1681;BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB1681; x-forefront-prvs: 01208B1E18 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(24454002)(189002)(199003)(54356999)(76576001)(74316002)(81166006)(81156014)(8676002)(33656002)(3660700001)(305945005)(68736007)(7846002)(575784001)(76176999)(50986999)(7736002)(101416001)(122556002)(5001770100001)(99286002)(97736004)(189998001)(3280700002)(105586002)(586003)(7696004)(86362001)(3846002)(102836003)(6116002)(2900100001)(106356001)(2906002)(106116001)(8936002)(87936001)(77096005)(66066001)(9686002)(4326007)(92566002)(5660300001);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR02MB1681;H:BLUPR02MB1683.namprd02.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Nov 2016 15:04:43.2945 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR02MB1681 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uA8GcovY008815 On 11/08/16 00:45, Johannes Thumshirn wrote: > Commit 540eb1eef 'scsi: libfc: fix seconds_since_last_reset calculation' > removed the use of 'struct timespec' from fc_get_host_stats(). This broke the > output of 'fcoeadm -s' after kernel 4.8-rc1 as lport->boot_time - jiffies > could become negative as in this example: > > $ cat /sys/class/fc_host/host8/statistics/seconds_since_last_reset > 0x10624dd2f1977b4 > > Take this into account so > /sys/class/fc_host/hostX/statistics/seconds_since_last_reset is sane again. > > Fixes: 540eb1eef ('scsi: libfc: fix seconds_since_last_reset calculation') > Signed-off-by: Johannes Thumshirn > Tested-by: Holger Schranz > --- > drivers/scsi/libfc/fc_lport.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c > index 04ce7cf..475c0a9 100644 > --- a/drivers/scsi/libfc/fc_lport.c > +++ b/drivers/scsi/libfc/fc_lport.c > @@ -304,11 +304,15 @@ struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) > unsigned int cpu; > u64 fcp_in_bytes = 0; > u64 fcp_out_bytes = 0; > + unsigned long boot_time = lport->boot_time; > > fc_stats = &lport->host_stats; > memset(fc_stats, 0, sizeof(struct fc_host_statistics)); > > - fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) / HZ; > + if (boot_time > jiffies) > + fc_stats->seconds_since_last_reset = (boot_time - jiffies) / HZ; > + else > + fc_stats->seconds_since_last_reset = (jiffies - boot_time) / HZ; > > for_each_possible_cpu(cpu) { > struct fc_stats *stats; Hello Johannes, I think the above code will miscalculate seconds_since_last_reset if 'jiffies' wraps around after an lport has been created and before seconds_since_last_reset is computed. Shouldn't seconds_since_last_reset be computed as follows? fc_stats->seconds_since_last_reset = (jiffies - boot_time) / HZ; Bart.