Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp823853imm; Wed, 26 Sep 2018 07:21:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV62WOSo9zOYcGWAu4CH9zaHNiVl8qAx+AnHDFUM2BRMI4rZ92BMYpDcPNs9J0vxOyVuTN6QN X-Received: by 2002:a63:f110:: with SMTP id f16-v6mr5956602pgi.236.1537971676538; Wed, 26 Sep 2018 07:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537971676; cv=none; d=google.com; s=arc-20160816; b=vo1Zjgi0irUZkBeLYuFBvE5VCs+b1evKf+rJk7cwGmk6H0VCTxR9iaz73EMmjoRHIh mRlHrqyY7fJfxCsairkXzqQ27CinJgMOmoaYlL06MrGr23sooDw8Wz5kfef742/eBTi8 VL+68hWk8LEaNcL5ThtWgMdroRYuB31ez6IMiC8h74t5dGsQxRhH+5Rf8UoGIylRJpCG lxnepmBHw7zIRrdvXALpALR6KbaC1e9oIEBiXWjHEr3PjxHD72cFTsZE2yCLZrhB5hvM QnWdE7fJxHJ/tXZZfDL75KdvzTFHRXIqVymheflg1xKEEzka8LPYs2lZXoQVz5C9qlqc ufNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=e5mRtNWxX6F5SMChsPDMrLDfPvr5I4nKsy8JJDKaFoo=; b=ICFWhJBMYw1pL3vHmtBq49q3jIUCB5AeSAaxYaBAOQzQFDfA3nG1ticXpKsvDk4gx2 ieIOZE73k4510SB4kdpwNjvdtWyTosiga1vBeYPiHZPuxqOATCcCYlYyPQ7904Vt3J0F KmmmehQaYPGvjtAJIYtZ+YFFYHTG/X+aihaChq7yxc1aeKFp9KYqAfJlLMlqutfcF+EX AfD3KWdQXIm6xUbfatoMH0ZYddjKIb9o2LqEOnW0wgZ1eyaIQpNyGboBF0zThMbVJfmZ 0Wilh+Aj97Y6YVK4w4dAIt7vrFl+HlwkzzQAsOYzuIdKY+7zgrcdV1ZpZxTc6D+emmuQ DVzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c12-v6si5151671plz.456.2018.09.26.07.21.00; Wed, 26 Sep 2018 07:21:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbeIZUcg (ORCPT + 99 others); Wed, 26 Sep 2018 16:32:36 -0400 Received: from mga12.intel.com ([192.55.52.136]:48800 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727017AbeIZUcg (ORCPT ); Wed, 26 Sep 2018 16:32:36 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2018 07:19:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,306,1534834800"; d="scan'208";a="266869055" Received: from rbhardw1-mobl.gar.corp.intel.com (HELO [10.252.74.64]) ([10.252.74.64]) by fmsmga006.fm.intel.com with ESMTP; 26 Sep 2018 07:19:22 -0700 Subject: Re: [PATCH 3/4] platform/x86: intel_pmc_core: Decode Snoop / Non Snoop LTR To: Andy Shevchenko Cc: Platform Driver , Darren Hart , Andy Shevchenko , Linux Kernel Mailing List , Rajneesh Bhardwaj , Souvik Kumar Chakravarty References: <20180903180415.31575-1-rajneesh.bhardwaj@linux.intel.com> <20180903180415.31575-3-rajneesh.bhardwaj@linux.intel.com> From: "Bhardwaj, Rajneesh" Message-ID: Date: Wed, 26 Sep 2018 19:49:21 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26-Sep-18 7:23 PM, Andy Shevchenko wrote: > On Mon, Sep 3, 2018 at 9:05 PM Rajneesh Bhardwaj > wrote: >> The LTR values follow PCIE LTR encoding format and can be decoded as per >> https://pcisig.com/sites/default/files/specification_documents/ECN_LatencyTolnReporting_14Aug08.pdf >> >> This adds support to translate the raw LTR values as read from the PMC >> to meaningful values in nanosecond units of time. >> +static void get_ltr_scale(u32 *val) > What's wrong to return converted value? Actually the name should > reflect what it does, ie *convert* value. I can change it as per your suggestion. > >> +{ >> + /* >> + * As per PCIE specification supprting document > supporting oops. Will fix. > >> + * ECN_LatencyTolnReporting_14Aug08.pdf the Latency >> + * Tolerance Reporting data payload is encoded in a >> + * 3 bit scale and 10 bit value fields. Values are >> + * multiplied by the indicated scale to yield an absolute time >> + * value, expressible in a range from 1 nanosecond to >> + * 2^25*(2^10-1) = 34,326,183,936 nanoseconds. >> + * >> + * scale encoding is as follows: >> + * >> + * ---------------------------------------------- >> + * |scale factor | Multiplier (ns) | >> + * ---------------------------------------------- >> + * | 0 | 1 | >> + * | 1 | 32 | >> + * | 2 | 1024 | >> + * | 3 | 32768 | >> + * | 4 | 1048576 | >> + * | 5 | 33554432 | >> + * | 6 | Invalid | >> + * | 7 | Invalid | >> + * ---------------------------------------------- >> + */ >> + if (*val > 5) { >> + *val = 0; >> + pr_warn("Invalid LTR scale factor.\n"); >> + } else { >> + *val = 1U << (5 * (*val)); >> + } >> +} >> + >> static int pmc_core_ltr_show(struct seq_file *s, void *unused) >> { >> struct pmc_dev *pmcdev = s->private; >> const struct pmc_bit_map *map = pmcdev->map->ltr_show_sts; >> + u64 decoded_snoop_ltr = 0, decoded_non_snoop_ltr = 0; >> + union ltr_payload ltr_data; >> + u32 scale = 0; > Redundant assignment. Ok > >> int index; >> >> for (index = 0; map[index].name ; index++) { >> - seq_printf(s, "%-32s\tRAW LTR: 0x%x\n", >> + ltr_data.raw_data = pmc_core_reg_read(pmcdev, >> + map[index].bit_mask); >> + >> + if (ltr_data.bits.non_snoop_req) { >> + scale = ltr_data.bits.non_snoop_scale; >> + get_ltr_scale(&scale); >> + decoded_non_snoop_ltr = >> + ltr_data.bits.non_snoop_val * scale; >> + } >> + >> + if (ltr_data.bits.snoop_req) { >> + scale = ltr_data.bits.snoop_scale; >> + get_ltr_scale(&scale); >> + decoded_snoop_ltr = >> + ltr_data.bits.snoop_val * scale; >> + } >> + >> + seq_printf(s, "%-24s\tRaw LTR: 0x%-16x\t Non-Snoop LTR (ns): %-16llu\t Snoop LTR (ns): %-16llu\n", >> map[index].name, >> - pmc_core_reg_read(pmcdev, map[index].bit_mask)); >> + ltr_data.raw_data, >> + decoded_non_snoop_ltr, >> + decoded_snoop_ltr); >> + >> + decoded_snoop_ltr = decoded_non_snoop_ltr = 0; > You may do this at the beginning of the loop and get rid of assignment > in the definition block. Fine. > >> } >> return 0; >> } >> +union ltr_payload { >> + u32 raw_data; >> + struct { >> + u32 snoop_val : 10; >> + u32 snoop_scale : 3; >> + u32 snoop_res : 2; >> + u32 snoop_req : 1; >> + u32 non_snoop_val : 10; >> + u32 non_snoop_scale : 3; >> + u32 non_snoop_res : 2; >> + u32 non_snoop_req : 1; >> + } bits; >> +}; > Just use normal masks and shifts. I chose union over masks and shifts to reduce code size and ensured correct endian-ness. Just for my understanding, can you please let me know why you feel masks/shift are better suited here? >