* Style cleanup.

* Made an enum out of the mailbox type.
* Rearranged some code to get rid of CID 1328 which was not a bug, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38209 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-08-17 19:07:16 +00:00
parent 352fb78f1f
commit 9189743037
+71 -64
View File
@@ -1,6 +1,6 @@
/*
* Copyright 2008-2009, Ingo Weinhold, [email protected].
* Copyright 2002-2009, Axel Dörfler, [email protected].
* Copyright 2002-2010, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
@@ -67,8 +67,10 @@ struct smp_msg {
uint32 proc_bitmap;
};
#define MAILBOX_LOCAL 1
#define MAILBOX_BCAST 2
enum mailbox_source {
MAILBOX_LOCAL,
MAILBOX_BCAST,
};
static vint32 sBootCPUSpin = 0;
@@ -448,7 +450,8 @@ release_spinlock(spinlock *lock)
if (sNumCPUs > 1) {
if (are_interrupts_enabled())
panic("release_spinlock: attempt to release lock %p with interrupts enabled\n", lock);
panic("release_spinlock: attempt to release lock %p with "
"interrupts enabled\n", lock);
#if B_DEBUG_SPINLOCK_CONTENTION
{
int32 count = atomic_and(&lock->lock, 0) - 1;
@@ -468,8 +471,10 @@ release_spinlock(spinlock *lock)
#endif
} else {
#if DEBUG_SPINLOCKS
if (are_interrupts_enabled())
panic("release_spinlock: attempt to release lock %p with interrupts enabled\n", lock);
if (are_interrupts_enabled()) {
panic("release_spinlock: attempt to release lock %p with "
"interrupts enabled\n", lock);
}
if (atomic_and((int32*)lock, 0) != 1)
panic("release_spinlock: lock %p was already released\n", lock);
#endif
@@ -480,11 +485,10 @@ release_spinlock(spinlock *lock)
}
/** Finds a free message and gets it.
* NOTE: has side effect of disabling interrupts
* return value is the former interrupt state
/*! Finds a free message and gets it.
NOTE: has side effect of disabling interrupts
return value is the former interrupt state
*/
static cpu_status
find_free_message(struct smp_msg** msg)
{
@@ -564,20 +568,19 @@ return_free_message(struct smp_msg *msg)
static struct smp_msg*
check_for_message(int currentCPU, int *source_mailbox)
check_for_message(int currentCPU, mailbox_source& sourceMailbox)
{
struct smp_msg *msg;
if (!sICIEnabled)
return NULL;
acquire_spinlock_nocheck(&sCPUMessageSpinlock[currentCPU]);
msg = sCPUMessages[currentCPU];
struct smp_msg* msg = sCPUMessages[currentCPU];
if (msg != NULL) {
sCPUMessages[currentCPU] = msg->next;
release_spinlock(&sCPUMessageSpinlock[currentCPU]);
TRACE((" cpu %d: found msg %p in cpu mailbox\n", currentCPU, msg));
*source_mailbox = MAILBOX_LOCAL;
sourceMailbox = MAILBOX_LOCAL;
} else {
// try getting one from the broadcast mailbox
@@ -594,49 +597,48 @@ check_for_message(int currentCPU, int *source_mailbox)
// mark it so we wont try to process this one again
msg->proc_bitmap = SET_BIT(msg->proc_bitmap, currentCPU);
*source_mailbox = MAILBOX_BCAST;
sourceMailbox = MAILBOX_BCAST;
break;
}
release_spinlock(&sBroadcastMessageSpinlock);
TRACE((" cpu %d: found msg %p in broadcast mailbox\n", currentCPU, msg));
TRACE((" cpu %d: found msg %p in broadcast mailbox\n", currentCPU,
msg));
}
return msg;
}
static void
finish_message_processing(int currentCPU, struct smp_msg *msg, int source_mailbox)
finish_message_processing(int currentCPU, struct smp_msg* msg,
mailbox_source sourceMailbox)
{
int old_refcount;
if (atomic_add(&msg->ref_count, -1) != 1)
return;
old_refcount = atomic_add(&msg->ref_count, -1);
if (old_refcount == 1) {
// we were the last one to decrement the ref_count
// it's our job to remove it from the list & possibly clean it up
struct smp_msg **mbox = NULL;
spinlock *spinlock = NULL;
struct smp_msg** mbox;
spinlock* spinlock;
// clean up the message from one of the mailboxes
switch (source_mailbox) {
case MAILBOX_BCAST:
if (sourceMailbox == MAILBOX_BCAST) {
mbox = &sBroadcastMessages;
spinlock = &sBroadcastMessageSpinlock;
break;
case MAILBOX_LOCAL:
} else {
mbox = &sCPUMessages[currentCPU];
spinlock = &sCPUMessageSpinlock[currentCPU];
break;
}
acquire_spinlock_nocheck(spinlock);
TRACE(("cleaning up message %p\n", msg));
if (source_mailbox != MAILBOX_BCAST) {
if (sourceMailbox != MAILBOX_BCAST) {
// local mailbox -- the message has already been removed in
// check_for_message()
} else if (msg == *mbox) {
(*mbox) = msg->next;
*mbox = msg->next;
} else {
// we need to walk to find the message in the list.
// we can't use any data found when previously walking through
@@ -663,7 +665,7 @@ finish_message_processing(int currentCPU, struct smp_msg *msg, int source_mailbo
if ((msg->flags & SMP_MSG_FLAG_FREE_ARG) != 0 && msg->data_ptr != NULL)
free(msg->data_ptr);
if (msg->flags & SMP_MSG_FLAG_SYNC) {
if ((msg->flags & SMP_MSG_FLAG_SYNC) != 0) {
msg->done = true;
// the caller cpu should now free the message
} else {
@@ -671,26 +673,24 @@ finish_message_processing(int currentCPU, struct smp_msg *msg, int source_mailbo
return_free_message(msg);
}
}
}
static int32
static status_t
process_pending_ici(int32 currentCPU)
{
struct smp_msg *msg;
bool haltCPU = false;
int sourceMailbox = 0;
int retval = B_HANDLED_INTERRUPT;
msg = check_for_message(currentCPU, &sourceMailbox);
mailbox_source sourceMailbox;
struct smp_msg* msg = check_for_message(currentCPU, sourceMailbox);
if (msg == NULL)
return B_ENTRY_NOT_FOUND;
TRACE((" cpu %ld message = %ld\n", currentCPU, msg->message));
bool haltCPU = false;
switch (msg->message) {
case SMP_MSG_INVALIDATE_PAGE_RANGE:
arch_cpu_invalidate_TLB_range((addr_t)msg->data, (addr_t)msg->data2);
arch_cpu_invalidate_TLB_range((addr_t)msg->data,
(addr_t)msg->data2);
break;
case SMP_MSG_INVALIDATE_PAGE_LIST:
arch_cpu_invalidate_TLB_list((addr_t*)msg->data, (int)msg->data2);
@@ -726,8 +726,11 @@ process_pending_ici(int32 currentCPU)
}
break;
}
default:
dprintf("smp_intercpu_int_handler: got unknown message %ld\n", msg->message);
dprintf("smp_intercpu_int_handler: got unknown message %ld\n",
msg->message);
break;
}
// finish dealing with this message, possibly removing it from the list
@@ -737,12 +740,13 @@ process_pending_ici(int32 currentCPU)
if (haltCPU)
debug_trap_cpu_in_kdl(currentCPU, false);
return retval;
return B_OK;
}
#if B_DEBUG_SPINLOCK_CONTENTION
static uint64
get_spinlock_counter(spinlock* lock)
{
@@ -780,6 +784,7 @@ spinlock_contention_syscall(const char* subsystem, uint32 function,
return B_OK;
}
#endif // B_DEBUG_SPINLOCK_CONTENTION
@@ -829,13 +834,14 @@ smp_intercpu_int_handler(int32 cpu)
void
smp_send_ici(int32 targetCPU, int32 message, uint32 data, uint32 data2, uint32 data3,
void *data_ptr, uint32 flags)
smp_send_ici(int32 targetCPU, int32 message, uint32 data, uint32 data2,
uint32 data3, void* dataPointer, uint32 flags)
{
struct smp_msg *msg;
TRACE(("smp_send_ici: target 0x%lx, mess 0x%lx, data 0x%lx, data2 0x%lx, data3 0x%lx, ptr %p, flags 0x%lx\n",
targetCPU, message, data, data2, data3, data_ptr, flags));
TRACE(("smp_send_ici: target 0x%lx, mess 0x%lx, data 0x%lx, data2 0x%lx, "
"data3 0x%lx, ptr %p, flags 0x%lx\n", targetCPU, message, data, data2,
data3, dataPointer, flags));
if (sICIEnabled) {
int state;
@@ -856,7 +862,7 @@ smp_send_ici(int32 targetCPU, int32 message, uint32 data, uint32 data2, uint32 d
msg->data = data;
msg->data2 = data2;
msg->data3 = data3;
msg->data_ptr = data_ptr;
msg->data_ptr = dataPointer;
msg->ref_count = 1;
msg->flags = flags;
msg->done = false;
@@ -869,7 +875,7 @@ smp_send_ici(int32 targetCPU, int32 message, uint32 data, uint32 data2, uint32 d
arch_smp_send_ici(targetCPU);
if (flags & SMP_MSG_FLAG_SYNC) {
if ((flags & SMP_MSG_FLAG_SYNC) != 0) {
// wait for the other cpu to finish processing it
// the interrupt handler will ref count it to <0
// if the message is sync after it has removed it from the mailbox
@@ -889,7 +895,7 @@ smp_send_ici(int32 targetCPU, int32 message, uint32 data, uint32 data2, uint32 d
void
smp_send_multicast_ici(cpu_mask_t cpuMask, int32 message, uint32 data,
uint32 data2, uint32 data3, void *data_ptr, uint32 flags)
uint32 data2, uint32 data3, void *dataPointer, uint32 flags)
{
if (!sICIEnabled)
return;
@@ -917,7 +923,7 @@ smp_send_multicast_ici(cpu_mask_t cpuMask, int32 message, uint32 data,
msg->data = data;
msg->data2 = data2;
msg->data3 = data3;
msg->data_ptr = data_ptr;
msg->data_ptr = dataPointer;
msg->ref_count = targetCPUs;
msg->flags = flags;
msg->proc_bitmap = ~cpuMask;
@@ -932,7 +938,7 @@ smp_send_multicast_ici(cpu_mask_t cpuMask, int32 message, uint32 data,
arch_smp_send_broadcast_ici();
// TODO: Introduce a call that only bothers the target CPUs!
if (flags & SMP_MSG_FLAG_SYNC) {
if ((flags & SMP_MSG_FLAG_SYNC) != 0) {
// wait for the other cpus to finish processing it
// the interrupt handler will ref count it to <0
// if the message is sync after it has removed it from the mailbox
@@ -952,12 +958,13 @@ smp_send_multicast_ici(cpu_mask_t cpuMask, int32 message, uint32 data,
void
smp_send_broadcast_ici(int32 message, uint32 data, uint32 data2, uint32 data3,
void *data_ptr, uint32 flags)
void *dataPointer, uint32 flags)
{
struct smp_msg *msg;
TRACE(("smp_send_broadcast_ici: cpu %ld mess 0x%lx, data 0x%lx, data2 0x%lx, data3 0x%lx, ptr %p, flags 0x%lx\n",
smp_get_current_cpu(), message, data, data2, data3, data_ptr, flags));
TRACE(("smp_send_broadcast_ici: cpu %ld mess 0x%lx, data 0x%lx, data2 "
"0x%lx, data3 0x%lx, ptr %p, flags 0x%lx\n", smp_get_current_cpu(),
message, data, data2, data3, dataPointer, flags));
if (sICIEnabled) {
int state;
@@ -972,14 +979,14 @@ smp_send_broadcast_ici(int32 message, uint32 data, uint32 data2, uint32 data3,
msg->data = data;
msg->data2 = data2;
msg->data3 = data3;
msg->data_ptr = data_ptr;
msg->data_ptr = dataPointer;
msg->ref_count = sNumCPUs - 1;
msg->flags = flags;
msg->proc_bitmap = SET_BIT(0, currentCPU);
msg->done = false;
TRACE(("smp_send_broadcast_ici%d: inserting msg %p into broadcast mbox\n",
currentCPU, msg));
TRACE(("smp_send_broadcast_ici%d: inserting msg %p into broadcast "
"mbox\n", currentCPU, msg));
// stick it in the appropriate cpu's mailbox
acquire_spinlock_nocheck(&sBroadcastMessageSpinlock);
@@ -991,7 +998,7 @@ smp_send_broadcast_ici(int32 message, uint32 data, uint32 data2, uint32 data3,
TRACE(("smp_send_broadcast_ici: sent interrupt\n"));
if (flags & SMP_MSG_FLAG_SYNC) {
if ((flags & SMP_MSG_FLAG_SYNC) != 0) {
// wait for the other cpus to finish processing it
// the interrupt handler will ref count it to <0
// if the message is sync after it has removed it from the mailbox
@@ -1018,14 +1025,14 @@ smp_send_broadcast_ici(int32 message, uint32 data, uint32 data2, uint32 data3,
void
smp_send_broadcast_ici_interrupts_disabled(int32 currentCPU, int32 message,
uint32 data, uint32 data2, uint32 data3, void *data_ptr, uint32 flags)
uint32 data, uint32 data2, uint32 data3, void *dataPointer, uint32 flags)
{
if (!sICIEnabled)
return;
TRACE(("smp_send_broadcast_ici_interrupts_disabled: cpu %ld mess 0x%lx, "
"data 0x%lx, data2 0x%lx, data3 0x%lx, ptr %p, flags 0x%lx\n",
currentCPU, message, data, data2, data3, data_ptr, flags));
currentCPU, message, data, data2, data3, dataPointer, flags));
struct smp_msg *msg;
find_free_message_interrupts_disabled(currentCPU, &msg);
@@ -1034,7 +1041,7 @@ smp_send_broadcast_ici_interrupts_disabled(int32 currentCPU, int32 message,
msg->data = data;
msg->data2 = data2;
msg->data3 = data3;
msg->data_ptr = data_ptr;
msg->data_ptr = dataPointer;
msg->ref_count = sNumCPUs - 1;
msg->flags = flags;
msg->proc_bitmap = SET_BIT(0, currentCPU);
@@ -1054,7 +1061,7 @@ smp_send_broadcast_ici_interrupts_disabled(int32 currentCPU, int32 message,
TRACE(("smp_send_broadcast_ici_interrupts_disabled %ld: sent interrupt\n",
currentCPU));
if (flags & SMP_MSG_FLAG_SYNC) {
if ((flags & SMP_MSG_FLAG_SYNC) != 0) {
// wait for the other cpus to finish processing it
// the interrupt handler will ref count it to <0
// if the message is sync after it has removed it from the mailbox
@@ -1226,8 +1233,7 @@ smp_get_current_cpu(void)
}
// #pragma mark -
// public exported functions
// #pragma mark - public exported functions
void
@@ -1252,6 +1258,7 @@ call_all_cpus(void (*func)(void *, int), void *cookie)
restore_interrupts(state);
}
void
call_all_cpus_sync(void (*func)(void*, int), void* cookie)
{