Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3876829ybz; Mon, 4 May 2020 11:20:04 -0700 (PDT) X-Google-Smtp-Source: APiQypJwGpoY8zZ2z8f2CTrGLkdwkwb2OQlnSzEVgO6ucxxRP+T8GEaLRRIoUkLIN7Q9dQCccuOJ X-Received: by 2002:a17:906:70f:: with SMTP id y15mr16192521ejb.276.1588616404289; Mon, 04 May 2020 11:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588616404; cv=none; d=google.com; s=arc-20160816; b=pz7kZeMbYApeTTW5hrtT6N6yJAj4EoZ/f73B9gGzszJOo+zQcXXztlIYpo5/Gm/gdE wLIgqfBoTo5z657Uh3NNFFUesjpZeIZdC23mrsQzuq/ny1FAzEdcfNrADnP8fE+CnpDn wMc+zmtpoo9N7yU1yAqeQCDIPrAZZZBvxwQp1EThWu/9kts6fyXcatZc9SnpSRiVetAb vOqUJ+PYC5LsnNjlTcNg1zQVp6RSs8v4eBOnUZiJ0BQpRswSqUmWPJ4tl/2hLaBr8IwW /3gsVFUDNYnavzVYhHE/Z6OQy7ec3MCVNFvKSj1diiOJ282CCiAqWt3YLxuadx9cR4Qc TB7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=2XCSpR+l3TstdzRVMz80y/2yb+BKpJZkEQ72F5IeDJk=; b=wyZhz4Ow8GWKKc8xs/Y9KKjRatEDnqg3B2U575/xEJYOxYTLKB9m0L/FdmZnV/Xun3 St7E84QO4sh5FvV2EAu6C80G7g+G88HZ4GO+5fBnDh1vGo7U+tlm28xSiQyr9LaDOWt6 Iq7fZbVXr8NrQCALjPW0eGlPGmzvo5hijR5cw0CCl58o5Gxu8rZGKBibQ86SB33gqV4s AYA6koRwQoyMbQ0BQVovy23toRdmIVqWPhMH2KUhmA+xZMNJPcFpZD3w+/CRhbwNd3jn C0cBaMoJm7eEa62/udNXQtJD6Nre4EAEyaeURQEbpbf1tnvzVPFWEgjTRXrfZe+zWf7J lzhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id r20si8317355edv.435.2020.05.04.11.19.41; Mon, 04 May 2020 11:20:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1732400AbgEDSQr (ORCPT + 99 others); Mon, 4 May 2020 14:16:47 -0400 Received: from mga12.intel.com ([192.55.52.136]:27145 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732278AbgEDSQo (ORCPT ); Mon, 4 May 2020 14:16:44 -0400 IronPort-SDR: OphSXnXIigcuahTUBJ6R4Xomb3S2mYLZ/GjwWJQMrV8+KikGCrfNiEBfl/Jq2admAt0QkYHEbL cvhqS86rQgWQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2020 11:16:34 -0700 IronPort-SDR: dNMkY38EIkVXXa27TiyYYe6z7BrjLhUlmnlPlboysHT6WLyDfmGS7ojOVc1TzjIpr7OlrMWib6 UBwG1bEKSyLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,352,1583222400"; d="scan'208";a="259427135" Received: from spandruv-mobl.amr.corp.intel.com ([10.212.145.237]) by orsmga003.jf.intel.com with ESMTP; 04 May 2020 11:16:33 -0700 From: Srinivas Pandruvada To: rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Srinivas Pandruvada Subject: [RFC][PATCH 4/5] thermal: Add support for setting polling interval Date: Mon, 4 May 2020 11:16:15 -0700 Message-Id: <20200504181616.175477-5-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200504181616.175477-1-srinivas.pandruvada@linux.intel.com> References: <20200504181616.175477-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add new attribute in the thermal syfs for setting temperature sampling interval when CONFIG_THERMAL_USER_EVENT_INTERFACE is defined. The default value is 0, which means no polling. At this interval user space will get an event THERMAL_TEMP_SAMPLE with temperature sample. This reuses existing polling mecahnism when polling or passive delay is specified during zone registry. To avoid interference with passive and polling delay, this new polling attribute can't be used for those zones. Signed-off-by: Srinivas Pandruvada --- drivers/thermal/thermal_core.c | 7 +++++++ drivers/thermal/thermal_sysfs.c | 36 +++++++++++++++++++++++++++++++-- include/linux/thermal.h | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 14770d882d42..17cd799b0073 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -313,6 +313,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz) thermal_zone_device_set_polling(tz, tz->passive_delay); else if (tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); + else if (tz->temp_polling_delay) + thermal_zone_device_set_polling(tz, tz->temp_polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -446,6 +448,11 @@ static void update_temperature(struct thermal_zone_device *tz) tz->temperature = temp; mutex_unlock(&tz->lock); + if (tz->temp_polling_delay) { + thermal_dev_send_event(tz->id, THERMAL_TEMP_SAMPLE, temp); + monitor_thermal_zone(tz); + } + trace_thermal_temperature(tz); if (tz->last_temperature == THERMAL_TEMP_INVALID) dev_dbg(&tz->device, "last_temperature N/A, current_temperature=%d\n", diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa85424c3ac4..0df7997993fe 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -248,6 +248,36 @@ create_thres_attr(temp_thres_low); create_thres_attr(temp_thres_high); create_thres_attr(temp_thres_hyst); +static ssize_t +temp_polling_delay_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct thermal_zone_device *tz = to_thermal_zone(dev); + int val; + + if (kstrtoint(buf, 10, &val)) + return -EINVAL; + + if (val && val < 1000) + return -EINVAL; + + tz->temp_polling_delay = val; + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return count; +} + +static ssize_t +temp_polling_delay_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct thermal_zone_device *tz = to_thermal_zone(dev); + + return sprintf(buf, "%d\n", tz->temp_polling_delay); +} + +static DEVICE_ATTR_RW(temp_polling_delay); + static int create_user_events_attrs(struct thermal_zone_device *tz) { struct attribute **attrs; @@ -260,8 +290,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz) if (tz->ops->get_temp_thres_high) ++index; - /* One additional space for NULL */ - attrs = kcalloc(index + 1, sizeof(*attrs), GFP_KERNEL); + /* One additional space for NULL and temp_pollling_delay */ + attrs = kcalloc(index + 2, sizeof(*attrs), GFP_KERNEL); if (!attrs) return -ENOMEM; @@ -312,6 +342,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz) attrs[index] = &tz->threshold_attrs[index].attr.attr; ++index; } + if (!tz->polling_delay && !tz->passive_delay) + attrs[index++] = &dev_attr_temp_polling_delay.attr; attrs[index] = NULL; tz->threshold_attribute_group.attrs = attrs; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index ee9d79ace7ce..0ec4bd8c9c5c 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -216,6 +216,7 @@ struct thermal_zone_device { enum thermal_notify_event notify_event; struct attribute_group threshold_attribute_group; struct thermal_attr *threshold_attrs; + int temp_polling_delay; }; /** -- 2.25.4