Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

smp/hotplug: Hotplug state fail injection

Add a sysfs file to one-time fail a specific state. This can be used
to test the state rollback code paths.

Something like this (hotplug-up.sh):

#!/bin/bash

echo 0 > /debug/sched_debug
echo 1 > /debug/tracing/events/cpuhp/enable

ALL_STATES=`cat /sys/devices/system/cpu/hotplug/states | cut -d':' -f1`
STATES=${1:-$ALL_STATES}

for state in $STATES
do
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 0 > /debug/tracing/trace
echo Fail state: $state
echo $state > /sys/devices/system/cpu/cpu1/hotplug/fail
cat /sys/devices/system/cpu/cpu1/hotplug/fail
echo 1 > /sys/devices/system/cpu/cpu1/online

cat /debug/tracing/trace > hotfail-${state}.trace

sleep 1
done

Can be used to test for all possible rollback (barring multi-instance)
scenarios on CPU-up, CPU-down is a trivial modification of the above.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: bigeasy@linutronix.de
Cc: efault@gmx.de
Cc: rostedt@goodmis.org
Cc: max.byungchul.park@gmail.com
Link: https://lkml.kernel.org/r/20170920170546.972581715@infradead.org


authored by

Peter Zijlstra and committed by
Thomas Gleixner
1db49484 5ebe7742

+61 -2
+2 -1
include/linux/cpuhotplug.h
··· 22 22 */ 23 23 24 24 enum cpuhp_state { 25 - CPUHP_OFFLINE, 25 + CPUHP_INVALID = -1, 26 + CPUHP_OFFLINE = 0, 26 27 CPUHP_CREATE_THREADS, 27 28 CPUHP_PERF_PREPARE, 28 29 CPUHP_PERF_X86_PREPARE,
+59 -1
kernel/cpu.c
··· 52 52 struct cpuhp_cpu_state { 53 53 enum cpuhp_state state; 54 54 enum cpuhp_state target; 55 + enum cpuhp_state fail; 55 56 #ifdef CONFIG_SMP 56 57 struct task_struct *thread; 57 58 bool should_run; ··· 68 67 #endif 69 68 }; 70 69 71 - static DEFINE_PER_CPU(struct cpuhp_cpu_state, cpuhp_state); 70 + static DEFINE_PER_CPU(struct cpuhp_cpu_state, cpuhp_state) = { 71 + .fail = CPUHP_INVALID, 72 + }; 72 73 73 74 #if defined(CONFIG_LOCKDEP) && defined(CONFIG_SMP) 74 75 static struct lockdep_map cpuhp_state_up_map = ··· 162 159 int (*cbm)(unsigned int cpu, struct hlist_node *node); 163 160 int (*cb)(unsigned int cpu); 164 161 int ret, cnt; 162 + 163 + if (st->fail == state) { 164 + st->fail = CPUHP_INVALID; 165 + 166 + if (!(bringup ? step->startup.single : step->teardown.single)) 167 + return 0; 168 + 169 + return -EAGAIN; 170 + } 165 171 166 172 if (!step->multi_instance) { 167 173 WARN_ON_ONCE(lastp && *lastp); ··· 1817 1805 } 1818 1806 static DEVICE_ATTR(target, 0644, show_cpuhp_target, write_cpuhp_target); 1819 1807 1808 + 1809 + static ssize_t write_cpuhp_fail(struct device *dev, 1810 + struct device_attribute *attr, 1811 + const char *buf, size_t count) 1812 + { 1813 + struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id); 1814 + struct cpuhp_step *sp; 1815 + int fail, ret; 1816 + 1817 + ret = kstrtoint(buf, 10, &fail); 1818 + if (ret) 1819 + return ret; 1820 + 1821 + /* 1822 + * Cannot fail STARTING/DYING callbacks. 1823 + */ 1824 + if (cpuhp_is_atomic_state(fail)) 1825 + return -EINVAL; 1826 + 1827 + /* 1828 + * Cannot fail anything that doesn't have callbacks. 1829 + */ 1830 + mutex_lock(&cpuhp_state_mutex); 1831 + sp = cpuhp_get_step(fail); 1832 + if (!sp->startup.single && !sp->teardown.single) 1833 + ret = -EINVAL; 1834 + mutex_unlock(&cpuhp_state_mutex); 1835 + if (ret) 1836 + return ret; 1837 + 1838 + st->fail = fail; 1839 + 1840 + return count; 1841 + } 1842 + 1843 + static ssize_t show_cpuhp_fail(struct device *dev, 1844 + struct device_attribute *attr, char *buf) 1845 + { 1846 + struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id); 1847 + 1848 + return sprintf(buf, "%d\n", st->fail); 1849 + } 1850 + 1851 + static DEVICE_ATTR(fail, 0644, show_cpuhp_fail, write_cpuhp_fail); 1852 + 1820 1853 static struct attribute *cpuhp_cpu_attrs[] = { 1821 1854 &dev_attr_state.attr, 1822 1855 &dev_attr_target.attr, 1856 + &dev_attr_fail.attr, 1823 1857 NULL 1824 1858 }; 1825 1859