mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 01:04:19 +08:00
5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
239 lines
6.3 KiB
C
239 lines
6.3 KiB
C
/*
|
|
* LED Kernel Timer Trigger
|
|
*
|
|
* Copyright 2005-2006 Openedhand Ltd.
|
|
*
|
|
* Author: Richard Purdie <rpurdie@openedhand.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/list.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/device.h>
|
|
#include <linux/sysdev.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/leds.h>
|
|
#include <linux/slab.h>
|
|
#include "leds.h"
|
|
|
|
struct timer_trig_data {
|
|
int brightness_on; /* LED brightness during "on" period.
|
|
* (LED_OFF < brightness_on <= LED_FULL)
|
|
*/
|
|
unsigned long delay_on; /* milliseconds on */
|
|
unsigned long delay_off; /* milliseconds off */
|
|
struct timer_list timer;
|
|
};
|
|
|
|
static void led_timer_function(unsigned long data)
|
|
{
|
|
struct led_classdev *led_cdev = (struct led_classdev *) data;
|
|
struct timer_trig_data *timer_data = led_cdev->trigger_data;
|
|
unsigned long brightness;
|
|
unsigned long delay;
|
|
|
|
if (!timer_data->delay_on || !timer_data->delay_off) {
|
|
led_set_brightness(led_cdev, LED_OFF);
|
|
return;
|
|
}
|
|
|
|
brightness = led_get_brightness(led_cdev);
|
|
if (!brightness) {
|
|
/* Time to switch the LED on. */
|
|
brightness = timer_data->brightness_on;
|
|
delay = timer_data->delay_on;
|
|
} else {
|
|
/* Store the current brightness value to be able
|
|
* to restore it when the delay_off period is over.
|
|
*/
|
|
timer_data->brightness_on = brightness;
|
|
brightness = LED_OFF;
|
|
delay = timer_data->delay_off;
|
|
}
|
|
|
|
led_set_brightness(led_cdev, brightness);
|
|
|
|
mod_timer(&timer_data->timer, jiffies + msecs_to_jiffies(delay));
|
|
}
|
|
|
|
static ssize_t led_delay_on_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
|
struct timer_trig_data *timer_data = led_cdev->trigger_data;
|
|
|
|
return sprintf(buf, "%lu\n", timer_data->delay_on);
|
|
}
|
|
|
|
static ssize_t led_delay_on_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t size)
|
|
{
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
|
struct timer_trig_data *timer_data = led_cdev->trigger_data;
|
|
int ret = -EINVAL;
|
|
char *after;
|
|
unsigned long state = simple_strtoul(buf, &after, 10);
|
|
size_t count = after - buf;
|
|
|
|
if (isspace(*after))
|
|
count++;
|
|
|
|
if (count == size) {
|
|
if (timer_data->delay_on != state) {
|
|
/* the new value differs from the previous */
|
|
timer_data->delay_on = state;
|
|
|
|
/* deactivate previous settings */
|
|
del_timer_sync(&timer_data->timer);
|
|
|
|
/* try to activate hardware acceleration, if any */
|
|
if (!led_cdev->blink_set ||
|
|
led_cdev->blink_set(led_cdev,
|
|
&timer_data->delay_on, &timer_data->delay_off)) {
|
|
/* no hardware acceleration, blink via timer */
|
|
mod_timer(&timer_data->timer, jiffies + 1);
|
|
}
|
|
}
|
|
ret = count;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static ssize_t led_delay_off_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
|
struct timer_trig_data *timer_data = led_cdev->trigger_data;
|
|
|
|
return sprintf(buf, "%lu\n", timer_data->delay_off);
|
|
}
|
|
|
|
static ssize_t led_delay_off_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t size)
|
|
{
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
|
struct timer_trig_data *timer_data = led_cdev->trigger_data;
|
|
int ret = -EINVAL;
|
|
char *after;
|
|
unsigned long state = simple_strtoul(buf, &after, 10);
|
|
size_t count = after - buf;
|
|
|
|
if (isspace(*after))
|
|
count++;
|
|
|
|
if (count == size) {
|
|
if (timer_data->delay_off != state) {
|
|
/* the new value differs from the previous */
|
|
timer_data->delay_off = state;
|
|
|
|
/* deactivate previous settings */
|
|
del_timer_sync(&timer_data->timer);
|
|
|
|
/* try to activate hardware acceleration, if any */
|
|
if (!led_cdev->blink_set ||
|
|
led_cdev->blink_set(led_cdev,
|
|
&timer_data->delay_on, &timer_data->delay_off)) {
|
|
/* no hardware acceleration, blink via timer */
|
|
mod_timer(&timer_data->timer, jiffies + 1);
|
|
}
|
|
}
|
|
ret = count;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
|
|
static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
|
|
|
|
static void timer_trig_activate(struct led_classdev *led_cdev)
|
|
{
|
|
struct timer_trig_data *timer_data;
|
|
int rc;
|
|
|
|
timer_data = kzalloc(sizeof(struct timer_trig_data), GFP_KERNEL);
|
|
if (!timer_data)
|
|
return;
|
|
|
|
timer_data->brightness_on = led_get_brightness(led_cdev);
|
|
if (timer_data->brightness_on == LED_OFF)
|
|
timer_data->brightness_on = led_cdev->max_brightness;
|
|
led_cdev->trigger_data = timer_data;
|
|
|
|
init_timer(&timer_data->timer);
|
|
timer_data->timer.function = led_timer_function;
|
|
timer_data->timer.data = (unsigned long) led_cdev;
|
|
|
|
rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
|
|
if (rc)
|
|
goto err_out;
|
|
rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
|
|
if (rc)
|
|
goto err_out_delayon;
|
|
|
|
/* If there is hardware support for blinking, start one
|
|
* user friendly blink rate chosen by the driver.
|
|
*/
|
|
if (led_cdev->blink_set)
|
|
led_cdev->blink_set(led_cdev,
|
|
&timer_data->delay_on, &timer_data->delay_off);
|
|
|
|
return;
|
|
|
|
err_out_delayon:
|
|
device_remove_file(led_cdev->dev, &dev_attr_delay_on);
|
|
err_out:
|
|
led_cdev->trigger_data = NULL;
|
|
kfree(timer_data);
|
|
}
|
|
|
|
static void timer_trig_deactivate(struct led_classdev *led_cdev)
|
|
{
|
|
struct timer_trig_data *timer_data = led_cdev->trigger_data;
|
|
unsigned long on = 0, off = 0;
|
|
|
|
if (timer_data) {
|
|
device_remove_file(led_cdev->dev, &dev_attr_delay_on);
|
|
device_remove_file(led_cdev->dev, &dev_attr_delay_off);
|
|
del_timer_sync(&timer_data->timer);
|
|
kfree(timer_data);
|
|
}
|
|
|
|
/* If there is hardware support for blinking, stop it */
|
|
if (led_cdev->blink_set)
|
|
led_cdev->blink_set(led_cdev, &on, &off);
|
|
}
|
|
|
|
static struct led_trigger timer_led_trigger = {
|
|
.name = "timer",
|
|
.activate = timer_trig_activate,
|
|
.deactivate = timer_trig_deactivate,
|
|
};
|
|
|
|
static int __init timer_trig_init(void)
|
|
{
|
|
return led_trigger_register(&timer_led_trigger);
|
|
}
|
|
|
|
static void __exit timer_trig_exit(void)
|
|
{
|
|
led_trigger_unregister(&timer_led_trigger);
|
|
}
|
|
|
|
module_init(timer_trig_init);
|
|
module_exit(timer_trig_exit);
|
|
|
|
MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
|
|
MODULE_DESCRIPTION("Timer LED trigger");
|
|
MODULE_LICENSE("GPL");
|