2019-05-27 13:55:06 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2015-11-10 07:09:25 +07:00
|
|
|
/*
|
|
|
|
*
|
2019-04-05 00:43:17 +07:00
|
|
|
* Authors: Waiman Long <longman@redhat.com>
|
2015-11-10 07:09:25 +07:00
|
|
|
*/
|
|
|
|
|
2019-04-05 00:43:16 +07:00
|
|
|
#include "lock_events.h"
|
2015-11-10 07:09:25 +07:00
|
|
|
|
2019-04-05 00:43:17 +07:00
|
|
|
#ifdef CONFIG_LOCK_EVENT_COUNTS
|
|
|
|
#ifdef CONFIG_PARAVIRT_SPINLOCKS
|
2015-11-10 07:09:25 +07:00
|
|
|
/*
|
2019-04-05 00:43:17 +07:00
|
|
|
* Collect pvqspinlock locking event counts
|
2015-11-10 07:09:25 +07:00
|
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
2017-02-01 22:36:40 +07:00
|
|
|
#include <linux/sched/clock.h>
|
2015-11-10 07:09:25 +07:00
|
|
|
#include <linux/fs.h>
|
|
|
|
|
2019-04-05 00:43:16 +07:00
|
|
|
#define EVENT_COUNT(ev) lockevents[LOCKEVENT_ ## ev]
|
|
|
|
|
2015-11-10 07:09:25 +07:00
|
|
|
/*
|
2019-04-05 00:43:17 +07:00
|
|
|
* PV specific per-cpu counter
|
2015-11-10 07:09:25 +07:00
|
|
|
*/
|
|
|
|
static DEFINE_PER_CPU(u64, pv_kick_time);
|
|
|
|
|
|
|
|
/*
|
2019-04-05 00:43:17 +07:00
|
|
|
* Function to read and return the PV qspinlock counts.
|
2015-11-10 07:09:25 +07:00
|
|
|
*
|
|
|
|
* The following counters are handled specially:
|
2019-04-05 00:43:16 +07:00
|
|
|
* 1. pv_latency_kick
|
2015-11-10 07:09:25 +07:00
|
|
|
* Average kick latency (ns) = pv_latency_kick/pv_kick_unlock
|
2019-04-05 00:43:16 +07:00
|
|
|
* 2. pv_latency_wake
|
2015-11-10 07:09:25 +07:00
|
|
|
* Average wake latency (ns) = pv_latency_wake/pv_kick_wake
|
2019-04-05 00:43:16 +07:00
|
|
|
* 3. pv_hash_hops
|
2015-11-10 07:09:25 +07:00
|
|
|
* Average hops/hash = pv_hash_hops/pv_kick_unlock
|
|
|
|
*/
|
2019-04-05 00:43:17 +07:00
|
|
|
ssize_t lockevent_read(struct file *file, char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
2015-11-10 07:09:25 +07:00
|
|
|
{
|
|
|
|
char buf[64];
|
2019-04-05 00:43:16 +07:00
|
|
|
int cpu, id, len;
|
|
|
|
u64 sum = 0, kicks = 0;
|
2015-11-10 07:09:25 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the counter ID stored in file->f_inode->i_private
|
|
|
|
*/
|
2019-04-05 00:43:16 +07:00
|
|
|
id = (long)file_inode(file)->i_private;
|
2015-11-10 07:09:25 +07:00
|
|
|
|
2019-04-05 00:43:16 +07:00
|
|
|
if (id >= lockevent_num)
|
2015-11-10 07:09:25 +07:00
|
|
|
return -EBADF;
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
2019-04-05 00:43:16 +07:00
|
|
|
sum += per_cpu(lockevents[id], cpu);
|
2015-11-10 07:09:25 +07:00
|
|
|
/*
|
2019-04-05 00:43:16 +07:00
|
|
|
* Need to sum additional counters for some of them
|
2015-11-10 07:09:25 +07:00
|
|
|
*/
|
2019-04-05 00:43:16 +07:00
|
|
|
switch (id) {
|
2015-11-10 07:09:25 +07:00
|
|
|
|
2019-04-05 00:43:16 +07:00
|
|
|
case LOCKEVENT_pv_latency_kick:
|
|
|
|
case LOCKEVENT_pv_hash_hops:
|
|
|
|
kicks += per_cpu(EVENT_COUNT(pv_kick_unlock), cpu);
|
2015-11-10 07:09:25 +07:00
|
|
|
break;
|
|
|
|
|
2019-04-05 00:43:16 +07:00
|
|
|
case LOCKEVENT_pv_latency_wake:
|
|
|
|
kicks += per_cpu(EVENT_COUNT(pv_kick_wake), cpu);
|
2015-11-10 07:09:25 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 00:43:16 +07:00
|
|
|
if (id == LOCKEVENT_pv_hash_hops) {
|
2016-04-18 13:31:41 +07:00
|
|
|
u64 frac = 0;
|
2015-11-10 07:09:25 +07:00
|
|
|
|
2016-04-18 13:31:41 +07:00
|
|
|
if (kicks) {
|
2019-04-05 00:43:16 +07:00
|
|
|
frac = 100ULL * do_div(sum, kicks);
|
2016-04-18 13:31:41 +07:00
|
|
|
frac = DIV_ROUND_CLOSEST_ULL(frac, kicks);
|
|
|
|
}
|
2015-11-10 07:09:25 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a X.XX decimal number
|
|
|
|
*/
|
2019-04-05 00:43:16 +07:00
|
|
|
len = snprintf(buf, sizeof(buf) - 1, "%llu.%02llu\n",
|
|
|
|
sum, frac);
|
2015-11-10 07:09:25 +07:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Round to the nearest ns
|
|
|
|
*/
|
2019-04-05 00:43:16 +07:00
|
|
|
if ((id == LOCKEVENT_pv_latency_kick) ||
|
|
|
|
(id == LOCKEVENT_pv_latency_wake)) {
|
2015-11-10 07:09:25 +07:00
|
|
|
if (kicks)
|
2019-04-05 00:43:16 +07:00
|
|
|
sum = DIV_ROUND_CLOSEST_ULL(sum, kicks);
|
2015-11-10 07:09:25 +07:00
|
|
|
}
|
2019-04-05 00:43:16 +07:00
|
|
|
len = snprintf(buf, sizeof(buf) - 1, "%llu\n", sum);
|
2015-11-10 07:09:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PV hash hop count
|
|
|
|
*/
|
2019-04-05 00:43:16 +07:00
|
|
|
static inline void lockevent_pv_hop(int hopcnt)
|
2015-11-10 07:09:25 +07:00
|
|
|
{
|
2019-04-05 00:43:16 +07:00
|
|
|
this_cpu_add(EVENT_COUNT(pv_hash_hops), hopcnt);
|
2015-11-10 07:09:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Replacement function for pv_kick()
|
|
|
|
*/
|
|
|
|
static inline void __pv_kick(int cpu)
|
|
|
|
{
|
|
|
|
u64 start = sched_clock();
|
|
|
|
|
|
|
|
per_cpu(pv_kick_time, cpu) = start;
|
|
|
|
pv_kick(cpu);
|
2019-04-05 00:43:16 +07:00
|
|
|
this_cpu_add(EVENT_COUNT(pv_latency_kick), sched_clock() - start);
|
2015-11-10 07:09:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Replacement function for pv_wait()
|
|
|
|
*/
|
|
|
|
static inline void __pv_wait(u8 *ptr, u8 val)
|
|
|
|
{
|
|
|
|
u64 *pkick_time = this_cpu_ptr(&pv_kick_time);
|
|
|
|
|
|
|
|
*pkick_time = 0;
|
|
|
|
pv_wait(ptr, val);
|
|
|
|
if (*pkick_time) {
|
2019-04-05 00:43:16 +07:00
|
|
|
this_cpu_add(EVENT_COUNT(pv_latency_wake),
|
2015-11-10 07:09:25 +07:00
|
|
|
sched_clock() - *pkick_time);
|
2019-04-05 00:43:16 +07:00
|
|
|
lockevent_inc(pv_kick_wake);
|
2015-11-10 07:09:25 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define pv_kick(c) __pv_kick(c)
|
|
|
|
#define pv_wait(p, v) __pv_wait(p, v)
|
|
|
|
|
2019-04-05 00:43:17 +07:00
|
|
|
#endif /* CONFIG_PARAVIRT_SPINLOCKS */
|
|
|
|
|
|
|
|
#else /* CONFIG_LOCK_EVENT_COUNTS */
|
2015-11-10 07:09:25 +07:00
|
|
|
|
2019-04-05 00:43:16 +07:00
|
|
|
static inline void lockevent_pv_hop(int hopcnt) { }
|
2015-11-10 07:09:25 +07:00
|
|
|
|
2019-04-05 00:43:17 +07:00
|
|
|
#endif /* CONFIG_LOCK_EVENT_COUNTS */
|