qcom-charger: add support to watch storm of events

Storm watch provides a simple API for tracking the occurrence of event
storms.

An event storm is defined as a cluster of events where there are
X events with no more than Y milliseconds between them, where X and Y
are configurable per event.

Querying whether a storm has occurred marks a new event.

Change-Id: Idf4bb1421d0dbec295f92f84174cd4bbc6130250
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
This commit is contained in:
Nicholas Troast 2016-01-19 12:34:45 -08:00 committed by Subbaraman Narayanamurthy
parent b44b90ad4c
commit ada01758dc
3 changed files with 95 additions and 2 deletions

View file

@ -6,6 +6,6 @@ obj-$(CONFIG_SMB1351_USB_CHARGER) += smb1351-charger.o pmic-voter.o
obj-$(CONFIG_MSM_BCL_CTL) += msm_bcl.o
obj-$(CONFIG_MSM_BCL_PERIPHERAL_CTL) += bcl_peripheral.o
obj-$(CONFIG_BATTERY_BCL) += battery_current_limit.o
obj-$(CONFIG_QPNP_SMB2) += qpnp-smb2.o smb-lib.o pmic-voter.o
obj-$(CONFIG_SMB138X_CHARGER) += smb138x-charger.o smb-lib.o pmic-voter.o
obj-$(CONFIG_QPNP_SMB2) += qpnp-smb2.o smb-lib.o pmic-voter.o storm-watch.o
obj-$(CONFIG_SMB138X_CHARGER) += smb138x-charger.o smb-lib.o pmic-voter.o storm-watch.o
obj-$(CONFIG_QPNP_QNOVO) += qpnp-qnovo.o

View file

@ -0,0 +1,57 @@
/* Copyright (c) 2016 The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "storm-watch.h"
/**
* is_storming(): Check if an event is storming
*
* @data: Data for tracking an event storm
*
* The return value will be true if a storm has been detected and
* false if a storm was not detected.
*/
bool is_storming(struct storm_watch *data)
{
ktime_t curr_kt, delta_kt;
bool is_storming = false;
if (!data)
return false;
if (!data->enabled)
return false;
/* max storm count must be greater than 0 */
if (data->max_storm_count <= 0)
return false;
/* the period threshold must be greater than 0ms */
if (data->storm_period_ms <= 0)
return false;
curr_kt = ktime_get_boottime();
delta_kt = ktime_sub(curr_kt, data->last_kt);
if (ktime_to_ms(delta_kt) < data->storm_period_ms)
data->storm_count++;
else
data->storm_count = 0;
if (data->storm_count > data->max_storm_count) {
is_storming = true;
data->storm_count = 0;
}
data->last_kt = curr_kt;
return is_storming;
}

View file

@ -0,0 +1,36 @@
/* Copyright (c) 2016 The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef __STORM_WATCH_H
#define __STORM_WATCH_H
#include <linux/ktime.h>
/**
* Data used to track an event storm.
*
* @storm_period_ms: The maximum time interval between two events. If this limit
* is exceeded then the event chain will be broken and removed
* from consideration for a storm.
* @max_storm_count: The number of chained events required to trigger a storm.
* @storm_count: The current number of chained events.
* @last_kt: Kernel time of the last event seen.
*/
struct storm_watch {
bool enabled;
int storm_period_ms;
int max_storm_count;
int storm_count;
ktime_t last_kt;
};
bool is_storming(struct storm_watch *data);
#endif