acrn-hypervisor/hypervisor/common/softirq.c
Yin, Fengwei 11e67f1c4a softirq: move softirq from hv_main to interrupt context
softirq shouldn't be bounded to vcpu thread. One issue for this
is shell (based on timer) can't work if we don't start any guest.

This change also is trying best to make softirq handler running
with irq enabled.

Also update the irq disable/enabel in vmexit handler to align
with the usage in vcpu_thread.

Tracked-On: #3387
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2019-07-22 09:55:06 +08:00

66 lines
1.3 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <types.h>
#include <bits.h>
#include <cpu.h>
#include <per_cpu.h>
#include <softirq.h>
static softirq_handler softirq_handlers[NR_SOFTIRQS];
void init_softirq(void)
{
}
/*
* @pre: nr will not equal or large than NR_SOFTIRQS
*/
void register_softirq(uint16_t nr, softirq_handler handler)
{
softirq_handlers[nr] = handler;
}
/*
* @pre: nr will not equal or large than NR_SOFTIRQS
*/
void fire_softirq(uint16_t nr)
{
bitmap_set_lock(nr, &per_cpu(softirq_pending, get_pcpu_id()));
}
static void do_softirq_internal(uint16_t cpu_id)
{
volatile uint64_t *softirq_pending_bitmap =
&per_cpu(softirq_pending, cpu_id);
uint16_t nr = ffs64(*softirq_pending_bitmap);
while (nr < NR_SOFTIRQS) {
bitmap_clear_lock(nr, softirq_pending_bitmap);
(*softirq_handlers[nr])(cpu_id);
nr = ffs64(*softirq_pending_bitmap);
}
}
/*
* @pre: this function will only be called with irq disabled
*/
void do_softirq(void)
{
uint16_t cpu_id = get_pcpu_id();
if (per_cpu(softirq_servicing, cpu_id) == 0U) {
per_cpu(softirq_servicing, cpu_id) = 1U;
CPU_IRQ_ENABLE();
do_softirq_internal(cpu_id);
CPU_IRQ_DISABLE();
do_softirq_internal(cpu_id);
per_cpu(softirq_servicing, cpu_id) = 0U;
}
}