powerpc/powernv: process all OPAL event interrupts with kopald
Using irq_work for processing OPAL event interrupts is not necessary. irq_work is typically used to schedule work from NMI context, a softirq may be more appropriate. However OPAL events are not particularly performance or latency critical, so they can all be invoked by kopald. This patch removes the irq_work queueing, and instead wakes up kopald when there is an event to be processed. kopald processes interrupts individually, enabling irqs and calling cond_resched between each one to minimise latencies. Event handlers themselves should still use threaded handlers, workqueues, etc. as necessary to avoid high interrupts-off latencies within any single interrupt. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:
Родитель
ee03b9b447
Коммит
56c0b48b1e
|
@ -22,7 +22,6 @@
|
||||||
#include <linux/kthread.h>
|
#include <linux/kthread.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/irq_work.h>
|
|
||||||
|
|
||||||
#include <asm/machdep.h>
|
#include <asm/machdep.h>
|
||||||
#include <asm/opal.h>
|
#include <asm/opal.h>
|
||||||
|
@ -38,37 +37,47 @@ struct opal_event_irqchip {
|
||||||
unsigned long mask;
|
unsigned long mask;
|
||||||
};
|
};
|
||||||
static struct opal_event_irqchip opal_event_irqchip;
|
static struct opal_event_irqchip opal_event_irqchip;
|
||||||
|
static u64 last_outstanding_events;
|
||||||
static unsigned int opal_irq_count;
|
static unsigned int opal_irq_count;
|
||||||
static unsigned int *opal_irqs;
|
static unsigned int *opal_irqs;
|
||||||
|
|
||||||
static void opal_handle_irq_work(struct irq_work *work);
|
void opal_handle_events(void)
|
||||||
static u64 last_outstanding_events;
|
|
||||||
static struct irq_work opal_event_irq_work = {
|
|
||||||
.func = opal_handle_irq_work,
|
|
||||||
};
|
|
||||||
|
|
||||||
void opal_handle_events(uint64_t events)
|
|
||||||
{
|
{
|
||||||
int virq, hwirq = 0;
|
__be64 events = 0;
|
||||||
u64 mask = opal_event_irqchip.mask;
|
u64 e;
|
||||||
|
|
||||||
if (!in_irq() && (events & mask)) {
|
e = READ_ONCE(last_outstanding_events) & opal_event_irqchip.mask;
|
||||||
last_outstanding_events = events;
|
again:
|
||||||
irq_work_queue(&opal_event_irq_work);
|
while (e) {
|
||||||
return;
|
int virq, hwirq;
|
||||||
}
|
|
||||||
|
|
||||||
while (events & mask) {
|
hwirq = fls64(e) - 1;
|
||||||
hwirq = fls64(events) - 1;
|
e &= ~BIT_ULL(hwirq);
|
||||||
if (BIT_ULL(hwirq) & mask) {
|
|
||||||
virq = irq_find_mapping(opal_event_irqchip.domain,
|
local_irq_disable();
|
||||||
hwirq);
|
virq = irq_find_mapping(opal_event_irqchip.domain, hwirq);
|
||||||
if (virq)
|
if (virq) {
|
||||||
generic_handle_irq(virq);
|
irq_enter();
|
||||||
|
generic_handle_irq(virq);
|
||||||
|
irq_exit();
|
||||||
}
|
}
|
||||||
events &= ~BIT_ULL(hwirq);
|
local_irq_enable();
|
||||||
|
|
||||||
|
cond_resched();
|
||||||
}
|
}
|
||||||
|
last_outstanding_events = 0;
|
||||||
|
if (opal_poll_events(&events) != OPAL_SUCCESS)
|
||||||
|
return;
|
||||||
|
e = be64_to_cpu(events) & opal_event_irqchip.mask;
|
||||||
|
if (e)
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool opal_have_pending_events(void)
|
||||||
|
{
|
||||||
|
if (last_outstanding_events & opal_event_irqchip.mask)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void opal_event_mask(struct irq_data *d)
|
static void opal_event_mask(struct irq_data *d)
|
||||||
|
@ -78,24 +87,9 @@ static void opal_event_mask(struct irq_data *d)
|
||||||
|
|
||||||
static void opal_event_unmask(struct irq_data *d)
|
static void opal_event_unmask(struct irq_data *d)
|
||||||
{
|
{
|
||||||
__be64 events;
|
|
||||||
|
|
||||||
set_bit(d->hwirq, &opal_event_irqchip.mask);
|
set_bit(d->hwirq, &opal_event_irqchip.mask);
|
||||||
|
if (opal_have_pending_events())
|
||||||
opal_poll_events(&events);
|
opal_wake_poller();
|
||||||
last_outstanding_events = be64_to_cpu(events);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We can't just handle the events now with opal_handle_events().
|
|
||||||
* If we did we would deadlock when opal_event_unmask() is called from
|
|
||||||
* handle_level_irq() with the irq descriptor lock held, because
|
|
||||||
* calling opal_handle_events() would call generic_handle_irq() and
|
|
||||||
* then handle_level_irq() which would try to take the descriptor lock
|
|
||||||
* again. Instead queue the events for later.
|
|
||||||
*/
|
|
||||||
if (last_outstanding_events & opal_event_irqchip.mask)
|
|
||||||
/* Need to retrigger the interrupt */
|
|
||||||
irq_work_queue(&opal_event_irq_work);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int opal_event_set_type(struct irq_data *d, unsigned int flow_type)
|
static int opal_event_set_type(struct irq_data *d, unsigned int flow_type)
|
||||||
|
@ -136,16 +130,13 @@ static irqreturn_t opal_interrupt(int irq, void *data)
|
||||||
__be64 events;
|
__be64 events;
|
||||||
|
|
||||||
opal_handle_interrupt(virq_to_hw(irq), &events);
|
opal_handle_interrupt(virq_to_hw(irq), &events);
|
||||||
opal_handle_events(be64_to_cpu(events));
|
last_outstanding_events = be64_to_cpu(events);
|
||||||
|
if (opal_have_pending_events())
|
||||||
|
opal_wake_poller();
|
||||||
|
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void opal_handle_irq_work(struct irq_work *work)
|
|
||||||
{
|
|
||||||
opal_handle_events(last_outstanding_events);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int opal_event_match(struct irq_domain *h, struct device_node *node,
|
static int opal_event_match(struct irq_domain *h, struct device_node *node,
|
||||||
enum irq_domain_bus_token bus_token)
|
enum irq_domain_bus_token bus_token)
|
||||||
{
|
{
|
||||||
|
|
|
@ -540,21 +540,15 @@ int opal_hmi_exception_early(struct pt_regs *regs)
|
||||||
/* HMI exception handler called in virtual mode during check_irq_replay. */
|
/* HMI exception handler called in virtual mode during check_irq_replay. */
|
||||||
int opal_handle_hmi_exception(struct pt_regs *regs)
|
int opal_handle_hmi_exception(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
s64 rc;
|
|
||||||
__be64 evt = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if HMI event is available.
|
* Check if HMI event is available.
|
||||||
* if Yes, then call opal_poll_events to pull opal messages and
|
* if Yes, then wake kopald to process them.
|
||||||
* process them.
|
|
||||||
*/
|
*/
|
||||||
if (!local_paca->hmi_event_available)
|
if (!local_paca->hmi_event_available)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
local_paca->hmi_event_available = 0;
|
local_paca->hmi_event_available = 0;
|
||||||
rc = opal_poll_events(&evt);
|
opal_wake_poller();
|
||||||
if (rc == OPAL_SUCCESS && evt)
|
|
||||||
opal_handle_events(be64_to_cpu(evt));
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -757,14 +751,19 @@ static void __init opal_imc_init_dev(void)
|
||||||
static int kopald(void *unused)
|
static int kopald(void *unused)
|
||||||
{
|
{
|
||||||
unsigned long timeout = msecs_to_jiffies(opal_heartbeat) + 1;
|
unsigned long timeout = msecs_to_jiffies(opal_heartbeat) + 1;
|
||||||
__be64 events;
|
|
||||||
|
|
||||||
set_freezable();
|
set_freezable();
|
||||||
do {
|
do {
|
||||||
try_to_freeze();
|
try_to_freeze();
|
||||||
opal_poll_events(&events);
|
|
||||||
opal_handle_events(be64_to_cpu(events));
|
opal_handle_events();
|
||||||
schedule_timeout_interruptible(timeout);
|
|
||||||
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
|
if (opal_have_pending_events())
|
||||||
|
__set_current_state(TASK_RUNNING);
|
||||||
|
else
|
||||||
|
schedule_timeout(timeout);
|
||||||
|
|
||||||
} while (!kthread_should_stop());
|
} while (!kthread_should_stop());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -24,7 +24,8 @@ extern u32 pnv_get_supported_cpuidle_states(void);
|
||||||
|
|
||||||
extern void pnv_lpc_init(void);
|
extern void pnv_lpc_init(void);
|
||||||
|
|
||||||
extern void opal_handle_events(uint64_t events);
|
extern void opal_handle_events(void);
|
||||||
|
extern bool opal_have_pending_events(void);
|
||||||
extern void opal_event_shutdown(void);
|
extern void opal_event_shutdown(void);
|
||||||
|
|
||||||
bool cpu_core_split_required(void);
|
bool cpu_core_split_required(void);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче