pci: hotplug: cpqphp: convert to kthread infrastructure
Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
2d100fe8f6
commit
fa007d8beb
|
@ -37,6 +37,7 @@
|
||||||
#include <linux/smp_lock.h>
|
#include <linux/smp_lock.h>
|
||||||
#include <linux/pci.h>
|
#include <linux/pci.h>
|
||||||
#include <linux/pci_hotplug.h>
|
#include <linux/pci_hotplug.h>
|
||||||
|
#include <linux/kthread.h>
|
||||||
#include "cpqphp.h"
|
#include "cpqphp.h"
|
||||||
|
|
||||||
static u32 configure_new_device(struct controller* ctrl, struct pci_func *func,
|
static u32 configure_new_device(struct controller* ctrl, struct pci_func *func,
|
||||||
|
@ -45,34 +46,20 @@ static int configure_new_function(struct controller* ctrl, struct pci_func *func
|
||||||
u8 behind_bridge, struct resource_lists *resources);
|
u8 behind_bridge, struct resource_lists *resources);
|
||||||
static void interrupt_event_handler(struct controller *ctrl);
|
static void interrupt_event_handler(struct controller *ctrl);
|
||||||
|
|
||||||
static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
|
|
||||||
static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
|
|
||||||
static int event_finished;
|
|
||||||
static unsigned long pushbutton_pending; /* = 0 */
|
|
||||||
|
|
||||||
/* things needed for the long_delay function */
|
static struct task_struct *cpqhp_event_thread;
|
||||||
static struct semaphore delay_sem;
|
static unsigned long pushbutton_pending; /* = 0 */
|
||||||
static wait_queue_head_t delay_wait;
|
|
||||||
|
|
||||||
/* delay is in jiffies to wait for */
|
/* delay is in jiffies to wait for */
|
||||||
static void long_delay(int delay)
|
static void long_delay(int delay)
|
||||||
{
|
{
|
||||||
DECLARE_WAITQUEUE(wait, current);
|
/*
|
||||||
|
* XXX(hch): if someone is bored please convert all callers
|
||||||
/* only allow 1 customer into the delay queue at once
|
* to call msleep_interruptible directly. They really want
|
||||||
* yes this makes some people wait even longer, but who really cares?
|
* to specify timeouts in natural units and spend a lot of
|
||||||
* this is for _huge_ delays to make the hardware happy as the
|
* effort converting them to jiffies..
|
||||||
* signals bounce around
|
|
||||||
*/
|
*/
|
||||||
down (&delay_sem);
|
|
||||||
|
|
||||||
init_waitqueue_head(&delay_wait);
|
|
||||||
|
|
||||||
add_wait_queue(&delay_wait, &wait);
|
|
||||||
msleep_interruptible(jiffies_to_msecs(delay));
|
msleep_interruptible(jiffies_to_msecs(delay));
|
||||||
remove_wait_queue(&delay_wait, &wait);
|
|
||||||
|
|
||||||
up(&delay_sem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -955,8 +942,8 @@ irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schedule_flag) {
|
if (schedule_flag) {
|
||||||
up(&event_semaphore);
|
wake_up_process(cpqhp_event_thread);
|
||||||
dbg("Signal event_semaphore\n");
|
dbg("Waking even thread");
|
||||||
}
|
}
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
@ -1735,7 +1722,7 @@ static u32 remove_board(struct pci_func * func, u32 replace_flag, struct control
|
||||||
static void pushbutton_helper_thread(unsigned long data)
|
static void pushbutton_helper_thread(unsigned long data)
|
||||||
{
|
{
|
||||||
pushbutton_pending = data;
|
pushbutton_pending = data;
|
||||||
up(&event_semaphore);
|
wake_up_process(cpqhp_event_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1744,13 +1731,13 @@ static int event_thread(void* data)
|
||||||
{
|
{
|
||||||
struct controller *ctrl;
|
struct controller *ctrl;
|
||||||
|
|
||||||
daemonize("phpd_event");
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
dbg("!!!!event_thread sleeping\n");
|
dbg("!!!!event_thread sleeping\n");
|
||||||
down_interruptible (&event_semaphore);
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
dbg("event_thread woken finished = %d\n", event_finished);
|
schedule();
|
||||||
if (event_finished) break;
|
|
||||||
|
if (kthread_should_stop())
|
||||||
|
break;
|
||||||
/* Do stuff here */
|
/* Do stuff here */
|
||||||
if (pushbutton_pending)
|
if (pushbutton_pending)
|
||||||
cpqhp_pushbutton_thread(pushbutton_pending);
|
cpqhp_pushbutton_thread(pushbutton_pending);
|
||||||
|
@ -1759,38 +1746,24 @@ static int event_thread(void* data)
|
||||||
interrupt_event_handler(ctrl);
|
interrupt_event_handler(ctrl);
|
||||||
}
|
}
|
||||||
dbg("event_thread signals exit\n");
|
dbg("event_thread signals exit\n");
|
||||||
up(&event_exit);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int cpqhp_event_start_thread(void)
|
int cpqhp_event_start_thread(void)
|
||||||
{
|
{
|
||||||
int pid;
|
cpqhp_event_thread = kthread_run(event_thread, NULL, "phpd_event");
|
||||||
|
if (IS_ERR(cpqhp_event_thread)) {
|
||||||
/* initialize our semaphores */
|
|
||||||
init_MUTEX(&delay_sem);
|
|
||||||
init_MUTEX_LOCKED(&event_semaphore);
|
|
||||||
init_MUTEX_LOCKED(&event_exit);
|
|
||||||
event_finished=0;
|
|
||||||
|
|
||||||
pid = kernel_thread(event_thread, NULL, 0);
|
|
||||||
if (pid < 0) {
|
|
||||||
err ("Can't start up our event thread\n");
|
err ("Can't start up our event thread\n");
|
||||||
return -1;
|
return PTR_ERR(cpqhp_event_thread);
|
||||||
}
|
}
|
||||||
dbg("Our event thread pid = %d\n", pid);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cpqhp_event_stop_thread(void)
|
void cpqhp_event_stop_thread(void)
|
||||||
{
|
{
|
||||||
event_finished = 1;
|
kthread_stop(cpqhp_event_thread);
|
||||||
dbg("event_thread finish command given\n");
|
|
||||||
up(&event_semaphore);
|
|
||||||
dbg("wait for event_thread to exit\n");
|
|
||||||
down(&event_exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue