Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1949751img; Wed, 27 Feb 2019 08:09:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IYw4zaPgjzh7h6P3gWWnxnR/Q0jGxwvnvQaJYHzj+oyhm7biSAVPS+puv4ZMX6AJPsVInbq X-Received: by 2002:a62:be0b:: with SMTP id l11mr2466475pff.52.1551283772413; Wed, 27 Feb 2019 08:09:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551283772; cv=none; d=google.com; s=arc-20160816; b=pgkaqA9d+qGxYNMmWy26i7adgRoUqvUAsSPeR2UKltTu9MhIDu/8X7tFnIJ7hVCgSq n6xH3kiMeXGUceiM9rwCn3tngrlW1hpR9dWMTRDYJjwgyY2oV7Et9mw1eFbjzSYPwJCJ mJyVcqy9pRKLpIqHVxq95SgfgDEbYo+WNoc6krb3dDV3q/C4V/z4jKOSdbDmYCSqAp2S MjR5VMJpd7c+6vvjIMvyWz4bMaw6euPDPRkkRks8JnWIbaU+ouvySNLvmYxxW7qOJCT4 Je0/ba6kL73Tfo/bmbsDc3t4C61Fv3VAdE1UEvJiNAPbx+AvbgDFlMejbusBRRNhsqBn siYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Brd1QZmNmePe4c8JCqIh4kmSi+Y7bu4CD8F42drwiqY=; b=us/CmNfuGZXKjb30oOysMJq9OwQUdNKM6x6rpMiWcmeSm9TBulZU5aOVA+UPOFUrV0 IVfEMSuPTbDejwr4hIYEPE43mcl9E7TBXbeveBpOEG0K589v71ykxrIvPBQ6xac5In9A 0qyFoRuaY+CNBR3b1+e1O0WhzvwEUF/G3rfZw26nTO8WbwS/BiG6BUkrlXS68oCA3W21 w684ejhrkPS6y+A+XrrnzDZZ922oceoapkLLiAgFDg4He+hLxnMPS8YzIq2szeV+4uqE kIHt/pRlBM5cVbo90gYfbjmS+/ewCJQoeu87mNl+V61C9EEtes1UYOeUjAv4V6paadOC /EpQ== 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 a89si15778259pla.362.2019.02.27.08.09.16; Wed, 27 Feb 2019 08:09:32 -0800 (PST) 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 S1730253AbfB0QGp (ORCPT + 99 others); Wed, 27 Feb 2019 11:06:45 -0500 Received: from mga01.intel.com ([192.55.52.88]:6599 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729287AbfB0QFp (ORCPT ); Wed, 27 Feb 2019 11:05:45 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2019 08:05:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,420,1544515200"; d="scan'208";a="303011631" Received: from unknown (HELO luv-build.sc.intel.com) ([172.25.110.25]) by orsmga005.jf.intel.com with ESMTP; 27 Feb 2019 08:05:42 -0800 From: Ricardo Neri To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Ashok Raj , Andi Kleen , Peter Zijlstra , "Ravi V. Shankar" , x86@kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , Ricardo Neri , "H. Peter Anvin" , Tony Luck , Clemens Ladisch , Arnd Bergmann , Philippe Ombredanne , Kate Stewart , "Rafael J. Wysocki" Subject: [RFC PATCH v2 03/14] x86/hpet: Calculate ticks-per-second in a separate function Date: Wed, 27 Feb 2019 08:05:07 -0800 Message-Id: <1551283518-18922-4-git-send-email-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551283518-18922-1-git-send-email-ricardo.neri-calderon@linux.intel.com> References: <1551283518-18922-1-git-send-email-ricardo.neri-calderon@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is easier to compute the expiration times of an HPET timer by using its frequency (i.e., the number of times it ticks in a second) than its period, as given in the capabilities register. In addition to the HPET char driver, the HPET-based hardlockup detector will also need to know the timer's frequency. Thus, create a common function that both can use. Cc: "H. Peter Anvin" Cc: Ashok Raj Cc: Andi Kleen Cc: Tony Luck Cc: Clemens Ladisch Cc: Arnd Bergmann Cc: Philippe Ombredanne Cc: Kate Stewart Cc: "Rafael J. Wysocki" Cc: "Ravi V. Shankar" Cc: x86@kernel.org Signed-off-by: Ricardo Neri --- drivers/char/hpet.c | 31 +++++++++++++++++++++++++------ include/linux/hpet.h | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index 4a22b4b41aef..b73b68c0e127 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c @@ -836,6 +836,29 @@ static unsigned long hpet_calibrate(struct hpets *hpetp) return ret; } +u64 hpet_get_ticks_per_sec(u64 hpet_caps) +{ + u64 ticks_per_sec, period; + + period = (hpet_caps & HPET_COUNTER_CLK_PERIOD_MASK) >> + HPET_COUNTER_CLK_PERIOD_SHIFT; /* fs, 10^-15 */ + + /* + * The frequency is the reciprocal of the period. The period is given + * femtoseconds per second. Thus, prepare a dividend to obtain the + * frequency in ticks per second. + */ + + /* 10^15 femtoseconds per second */ + ticks_per_sec = 1000000000000000uLL; + ticks_per_sec += period >> 1; /* round */ + + /* The quotient is put in the dividend. We drop the remainder. */ + do_div(ticks_per_sec, period); + + return ticks_per_sec; +} + int hpet_alloc(struct hpet_data *hdp) { u64 cap, mcfg; @@ -845,7 +868,6 @@ int hpet_alloc(struct hpet_data *hdp) size_t siz; struct hpet __iomem *hpet; static struct hpets *last; - unsigned long period; unsigned long long temp; u32 remainder; @@ -881,6 +903,8 @@ int hpet_alloc(struct hpet_data *hdp) cap = readq(&hpet->hpet_cap); + temp = hpet_get_ticks_per_sec(cap); + ntimer = ((cap & HPET_NUM_TIM_CAP_MASK) >> HPET_NUM_TIM_CAP_SHIFT) + 1; if (hpetp->hp_ntimer != ntimer) { @@ -897,11 +921,6 @@ int hpet_alloc(struct hpet_data *hdp) last = hpetp; - period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >> - HPET_COUNTER_CLK_PERIOD_SHIFT; /* fs, 10^-15 */ - temp = 1000000000000000uLL; /* 10^15 femtoseconds per second */ - temp += period >> 1; /* round */ - do_div(temp, period); hpetp->hp_tick_freq = temp; /* ticks per second */ printk(KERN_INFO "hpet%d: at MMIO 0x%lx, IRQ%s", diff --git a/include/linux/hpet.h b/include/linux/hpet.h index 8604564b985d..e7b36bcf4699 100644 --- a/include/linux/hpet.h +++ b/include/linux/hpet.h @@ -107,5 +107,6 @@ static inline void hpet_reserve_timer(struct hpet_data *hd, int timer) } int hpet_alloc(struct hpet_data *); +u64 hpet_get_ticks_per_sec(u64 hpet_caps); #endif /* !__HPET__ */ -- 2.17.1