Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5705066 authored by Sauvik Saha's avatar Sauvik Saha
Browse files

netfilter: Add reset_timer logic to timers



-This patch reuses the existing reset_timer logic
while running IDLE and HARDIDLE timers.

CRs-Fixed: 2859971
Change-Id: Ibaa86a30ec4c58eb3fbc2f4f48c9c1af6f33f018
Acked-by: default avatarAkash Aggarwal <akasagga@qti.qualcomm.com>
Signed-off-by: default avatarManoj Basapathi <manojbm@codeaurora.org>
Signed-off-by: default avatarSauvik Saha <ssaha@codeaurora.org>
parent 787ab105
Loading
Loading
Loading
Loading
+50 −17
Original line number Diff line number Diff line
@@ -190,18 +190,18 @@ static ssize_t idletimer_tg_show(struct device *dev,
			time_diff = ktimespec.tv_sec;
		} else {
			expires = timer->timer.expires;
			time_diff = jiffies_to_msecs(expires -
						     now) / 1000;
			time_diff =
				jiffies_to_msecs(abs(expires - now)) / 1000;
		}
	}

	mutex_unlock(&list_mutex);

	if (time_after(expires, jiffies) || ktimespec.tv_sec > 0)
	if (time_after(expires, now) || ktimespec.tv_sec > 0)
		return scnprintf(buf, PAGE_SIZE, "%ld\n", time_diff);

	if (timer->send_nl_msg)
		return scnprintf(buf, PAGE_SIZE, "%ld\n", time_diff);
		return scnprintf(buf, PAGE_SIZE, "0 %ld\n", time_diff);
	else
		return scnprintf(buf, PAGE_SIZE, "0\n");
}
@@ -235,6 +235,7 @@ static enum alarmtimer_restart idletimer_tg_alarmproc(struct alarm *alarm,
	struct idletimer_tg *timer = alarm->data;

	pr_debug("alarm %s expired\n", timer->attr.attr.name);
	timer->active = false;
	schedule_work(&timer->work);
	return ALARMTIMER_NORESTART;
}
@@ -485,6 +486,48 @@ static void reset_timer(const struct idletimer_tg_info *info,
	spin_unlock_bh(&timestamp_lock);
}

static void reset_timer_v1(const struct idletimer_tg_info_v1 *info,
			   struct sk_buff *skb)
{
	unsigned long now = jiffies;
	struct idletimer_tg *timer = info->timer;
	bool timer_prev;

	spin_lock_bh(&timestamp_lock);
	timer_prev = timer->active;
	timer->active = true;
	/* timer_prev is used to guard overflow problem in time_before*/
	if (!timer_prev || time_before(timer->timer.expires, now)) {
		pr_debug("Starting timer (Expired, Jiffies): %lu, %lu\n",
			 timer->timer.expires, now);

		/* Stores the uid resposible for waking up the radio */
		if (skb && skb->sk) {
			timer->uid =
			from_kuid_munged(current_user_ns(),
					 sock_i_uid(skb_to_full_sk(skb)));
		}

		/* checks if there is a pending inactive notification*/
		if (timer->work_pending) {
			timer->delayed_timer_trigger = timer->last_modified_timer;
		} else {
			timer->work_pending = true;
			schedule_work(&timer->work);
		}
	}
	if (info->timer->timer_type & XT_IDLETIMER_ALARM) {
		ktime_t tout = ktime_set(info->timeout, 0);

		alarm_start_relative(&info->timer->alarm, tout);
	} else {
		timer->last_modified_timer = ktime_to_timespec64(ktime_get_boottime());
		mod_timer(&timer->timer,
			  msecs_to_jiffies(info->timeout * 1000) + now);
	}
	spin_unlock_bh(&timestamp_lock);
}

/*
 * The actual xt_tables plugin.
 */
@@ -523,15 +566,7 @@ static unsigned int idletimer_tg_target_v1(struct sk_buff *skb,

	BUG_ON(!info->timer);

	if (info->timer->timer_type & XT_IDLETIMER_ALARM) {
		ktime_t tout = ktime_set(info->timeout, 0);

		alarm_start_relative(&info->timer->alarm, tout);

	} else {
		mod_timer(&info->timer->timer,
			  msecs_to_jiffies(info->timeout * 1000) + jiffies);
	}
	reset_timer_v1(info, skb);

	return XT_CONTINUE;
}
@@ -629,9 +664,7 @@ static int idletimer_tg_checkentry_v1(const struct xt_tgchk_param *par)
				alarm_start_relative(&info->timer->alarm, tout);
			}
		} else {
			mod_timer(&info->timer->timer,
				  msecs_to_jiffies(info->timeout * 1000) +
				  jiffies);
			reset_timer_v1(info, NULL);
		}
		pr_debug("increased refcnt of timer %s to %u\n",
			 info->label, info->timer->refcnt);
@@ -692,8 +725,8 @@ static void idletimer_tg_destroy_v1(const struct xt_tgdtor_param *par)
			del_timer_sync(&info->timer->timer);
			unregister_pm_notifier(&info->timer->pm_nb);
		}
		cancel_work_sync(&info->timer->work);
		sysfs_remove_file(idletimer_tg_kobj, &info->timer->attr.attr);
		cancel_work_sync(&info->timer->work);
		kfree(info->timer->attr.attr.name);
		kfree(info->timer);
	} else {