From 2406849d4a8bcb152bc992bc5c1c6ef51e783f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20G=C3=BCnther?= Date: Tue, 27 Oct 2009 08:14:03 +0000 Subject: [PATCH] * Coding style fixes regarding whitespace usage. * Copyright style fixes. * Implemented FreeBSD hardclock subsystem, which is needed to update the ticks variable. The previous usage of "#define ticks system_time()" wasn't sufficient anymore, as there are drivers using the ticks name for local scoped variables. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33785 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/libs/compat/freebsd_network/Condvar.cpp | 8 +-- src/libs/compat/freebsd_network/Unit.cpp | 16 +++-- src/libs/compat/freebsd_network/clock.c | 75 +++++++++++++++----- src/libs/compat/freebsd_network/condvar.c | 2 +- src/libs/compat/freebsd_network/condvar.h | 4 +- src/libs/compat/freebsd_network/device.h | 4 +- src/libs/compat/freebsd_network/driver.c | 24 ++++--- src/libs/compat/freebsd_network/sleepqueue.c | 2 +- src/libs/compat/freebsd_network/synch.c | 4 +- src/libs/compat/freebsd_network/taskqueue.c | 8 +-- src/libs/compat/freebsd_network/timeout.c | 2 +- src/libs/compat/freebsd_network/unit.c | 29 ++++---- src/libs/compat/freebsd_network/unit.h | 4 +- 13 files changed, 116 insertions(+), 66 deletions(-) diff --git a/src/libs/compat/freebsd_network/Condvar.cpp b/src/libs/compat/freebsd_network/Condvar.cpp index 28c7b29fc3..652be6009d 100644 --- a/src/libs/compat/freebsd_network/Condvar.cpp +++ b/src/libs/compat/freebsd_network/Condvar.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de + * Copyright 2009 Colin Günther, coling@gmx.de * All Rights Reserved. Distributed under the terms of the MIT License. */ @@ -29,7 +29,7 @@ status_t init_condition_variables() { sConditionVariableCache = create_object_cache("condition variables", - sizeof (ConditionVariable), 0, NULL, NULL, NULL); + sizeof (ConditionVariable), 0, NULL, NULL, NULL); if (sConditionVariableCache == NULL) return B_NO_MEMORY; @@ -49,8 +49,8 @@ uninit_condition_variables() void _cv_init(struct cv* conditionVariable, const char* description) { - conditionVariable->condVar = - (ConditionVariable*)object_cache_alloc(sConditionVariableCache, 0); + conditionVariable->condVar + = (ConditionVariable*)object_cache_alloc(sConditionVariableCache, 0); conditionVariable->condVar->Init(NULL, description); } diff --git a/src/libs/compat/freebsd_network/Unit.cpp b/src/libs/compat/freebsd_network/Unit.cpp index 9099918c07..51a4598066 100644 --- a/src/libs/compat/freebsd_network/Unit.cpp +++ b/src/libs/compat/freebsd_network/Unit.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2009 Colin Günther, coling@gmx.de * All Rights Reserved. Distributed under the terms of the MIT License. * */ @@ -18,8 +18,8 @@ status_t -_new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) { - +_new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) +{ status_t status = B_OK; idStore->idBuffer = radix_bitmap_create(maxIdCount); @@ -31,14 +31,15 @@ _new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) { void -_delete_unrhdr_buffer_locked(struct unrhdr* idStore) { - +_delete_unrhdr_buffer_locked(struct unrhdr* idStore) +{ radix_bitmap_destroy(idStore->idBuffer); } int -_alloc_unr_locked(struct unrhdr* idStore) { +_alloc_unr_locked(struct unrhdr* idStore) +{ swap_addr_t slotIndex; int id = ID_STORE_FULL; @@ -52,7 +53,8 @@ _alloc_unr_locked(struct unrhdr* idStore) { void -_free_unr_locked(struct unrhdr* idStore, u_int identity) { +_free_unr_locked(struct unrhdr* idStore, u_int identity) +{ uint32 slotIndex = (int32)identity - idStore->idBias; radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1); diff --git a/src/libs/compat/freebsd_network/clock.c b/src/libs/compat/freebsd_network/clock.c index 1b11b03dc4..2543ac8a4b 100644 --- a/src/libs/compat/freebsd_network/clock.c +++ b/src/libs/compat/freebsd_network/clock.c @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2009, Colin Günther, coling@gmx.de * All rights reserved. Distributed under the terms of the MIT License. */ @@ -7,34 +7,75 @@ #include "device.h" +#define CONVERT_HZ_TO_USECS(hertz) (1000000LL / (hertz)) +#define FREEBSD_CLOCK_FREQUENCY_IN_HZ 1000 + + int ticks; -struct net_timer hardclockTimer; +static sem_id sHardClockSem; +static thread_id sHardClockThread; -void hardclock(struct net_timer*, void*); +/*! + * Implementation of FreeBSD's hardclock timer. + * + * Note: We are not using the FreeBSD variable hz as the invocation frequency + * as it is the case in FreeBSD's hardclock function. This is due to lower + * system load. The hz (see compat/sys/kernel.h) variable in the compat layer is + * set to 1000000 Hz, whereas it is usually set to 1000 Hz for FreeBSD. + */ +static status_t +hard_clock_thread(void* data) +{ + status_t status = B_OK; + const bigtime_t duration + = CONVERT_HZ_TO_USECS(FREEBSD_CLOCK_FREQUENCY_IN_HZ); + + do { + bigtime_t timeout = system_time() + duration; + status = acquire_sem_etc(sHardClockSem, 1, B_ABSOLUTE_TIMEOUT, timeout); + + if (system_time() >= timeout) { + atomic_add((vint32*)&ticks, 1); + } + } while (status != B_BAD_SEM_ID); + + return status; +} -// TODO use the hardclock function in the compat layer actually. status_t -init_clock() +init_hard_clock() { - gStack->init_timer(&hardclockTimer, &hardclock, NULL); - gStack->set_timer(&hardclockTimer, hz); + status_t status = B_OK; - return B_OK; + sHardClockSem = create_sem(0, "hard clock wait"); + if (sHardClockSem < B_OK) { + status = sHardClockSem; + goto error1; + } + + sHardClockThread = spawn_kernel_thread(hard_clock_thread, "hard clock", + B_NORMAL_PRIORITY, NULL); + if (sHardClockThread < B_OK) { + status = sHardClockThread; + goto error2; + } + + return resume_thread(sHardClockThread); + +error2: + delete_sem(sHardClockSem); +error1: + return status; } void -uninit_clock() +uninit_hard_clock() { - gStack->cancel_timer(&hardclockTimer); -} + status_t status; - -void -hardclock(struct net_timer* timer, void* argument) -{ - atomic_add((vint32*)&ticks, 1); - gStack->set_timer(&hardclockTimer, hz); + delete_sem(sHardClockSem); + wait_for_thread(sHardClockThread, &status); } diff --git a/src/libs/compat/freebsd_network/condvar.c b/src/libs/compat/freebsd_network/condvar.c index 0c78a2be78..5c07802fb1 100644 --- a/src/libs/compat/freebsd_network/condvar.c +++ b/src/libs/compat/freebsd_network/condvar.c @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2009 Colin Günther, coling@gmx.de. * All rights reserved. Distributed under the terms of the MIT License. */ diff --git a/src/libs/compat/freebsd_network/condvar.h b/src/libs/compat/freebsd_network/condvar.h index 8ed4ce6619..e0698474e0 100644 --- a/src/libs/compat/freebsd_network/condvar.h +++ b/src/libs/compat/freebsd_network/condvar.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de + * Copyright 2009 Colin Günther, coling@gmx.de * All Rights Reserved. Distributed under the terms of the MIT License. */ #ifndef CONDVAR_H_ @@ -12,7 +12,7 @@ extern "C" { void _cv_init(struct cv*, const char*); void _cv_wait_unlocked(struct cv *); -int _cv_timedwait_unlocked(struct cv*, int); +int _cv_timedwait_unlocked(struct cv*, int); void _cv_signal(struct cv*); #ifdef __cplusplus diff --git a/src/libs/compat/freebsd_network/device.h b/src/libs/compat/freebsd_network/device.h index 6599d777a6..f7f08f918c 100644 --- a/src/libs/compat/freebsd_network/device.h +++ b/src/libs/compat/freebsd_network/device.h @@ -67,8 +67,8 @@ void uninit_taskqueues(void); status_t init_condition_variables(void); void uninit_condition_variables(void); -status_t init_clock(void); -void uninit_clock(void); +status_t init_hard_clock(void); +void uninit_hard_clock(void); device_t find_root_device(int); diff --git a/src/libs/compat/freebsd_network/driver.c b/src/libs/compat/freebsd_network/driver.c index 515dc4d37e..3035b5b74c 100644 --- a/src/libs/compat/freebsd_network/driver.c +++ b/src/libs/compat/freebsd_network/driver.c @@ -149,29 +149,33 @@ _fbsd_init_driver(driver_t *driver) if (status < B_OK) return status; - status = init_mutexes(); + status = init_hard_clock(); if (status < B_OK) goto err1; - status = init_mbufs(); + status = init_mutexes(); if (status < B_OK) goto err2; + status = init_mbufs(); + if (status < B_OK) + goto err3; + init_bounce_pages(); status = init_condition_variables(); if (status < B_OK) - goto err3; + goto err4; if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) { status = init_taskqueues(); if (status < B_OK) - goto err4; + goto err5; } status = init_wlan_stack(); if (status < B_OK) - goto err5; + goto err6; while (gDeviceCount < MAX_DEVICES) { device_t root, device; @@ -209,15 +213,17 @@ _fbsd_init_driver(driver_t *driver) uninit_wlan_stack(); -err5: +err6: if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) uninit_taskqueues(); -err4: +err5: uninit_condition_variables(); -err3: +err4: uninit_mbufs(); -err2: +err3: uninit_mutexes(); +err2: + uninit_hard_clock(); err1: put_module(B_PCI_MODULE_NAME); return status; diff --git a/src/libs/compat/freebsd_network/sleepqueue.c b/src/libs/compat/freebsd_network/sleepqueue.c index 1e9eae8044..e01b770869 100644 --- a/src/libs/compat/freebsd_network/sleepqueue.c +++ b/src/libs/compat/freebsd_network/sleepqueue.c @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de + * Copyright 2009 Colin Günther, coling@gmx.de * All rights reserved. Distributed under the terms of the MIT License. */ diff --git a/src/libs/compat/freebsd_network/synch.c b/src/libs/compat/freebsd_network/synch.c index 9fb89d8bbf..ee88207dae 100644 --- a/src/libs/compat/freebsd_network/synch.c +++ b/src/libs/compat/freebsd_network/synch.c @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de + * Copyright 2009 Colin Günther, coling@gmx.de * All rights reserved. Distributed under the terms of the MIT License. */ @@ -9,7 +9,7 @@ #include -#define ticks_to_msecs(t) (1000 * (t) / hz) +#define ticks_to_msecs(t) (1000 * (t) / hz) int diff --git a/src/libs/compat/freebsd_network/taskqueue.c b/src/libs/compat/freebsd_network/taskqueue.c index 7f2f5e82ca..10b03bf104 100644 --- a/src/libs/compat/freebsd_network/taskqueue.c +++ b/src/libs/compat/freebsd_network/taskqueue.c @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2009, Colin Günther, coling@gmx.de * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. * @@ -16,9 +16,9 @@ #include -#define TQ_FLAGS_ACTIVE (1 << 0) -#define TQ_FLAGS_BLOCKED (1 << 1) -#define TQ_FLAGS_PENDING (1 << 2) +#define TQ_FLAGS_ACTIVE (1 << 0) +#define TQ_FLAGS_BLOCKED (1 << 1) +#define TQ_FLAGS_PENDING (1 << 2) struct taskqueue { diff --git a/src/libs/compat/freebsd_network/timeout.c b/src/libs/compat/freebsd_network/timeout.c index 08ec4532cd..dd6817ea92 100644 --- a/src/libs/compat/freebsd_network/timeout.c +++ b/src/libs/compat/freebsd_network/timeout.c @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2009, Colin Günther, coling@gmx.de * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. */ diff --git a/src/libs/compat/freebsd_network/unit.c b/src/libs/compat/freebsd_network/unit.c index f7c4c3bd67..0053875eef 100644 --- a/src/libs/compat/freebsd_network/unit.c +++ b/src/libs/compat/freebsd_network/unit.c @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2009 Colin Günther, coling@gmx.de * All Rights Reserved. Distributed under the terms of the MIT License. * */ @@ -19,12 +19,13 @@ extern struct mtx gIdStoreLock; struct unrhdr* -new_unrhdr(int low, int high, struct mtx* mutex) { +new_unrhdr(int low, int high, struct mtx* mutex) +{ struct unrhdr* idStore; uint32 maxIdCount = high - low + 1; KASSERT(low <= high, - ("ID-Store: use error: %s(%u, %u)", __func__, low, high)); + ("ID-Store: use error: %s(%u, %u)", __func__, low, high)); idStore = malloc(sizeof *idStore); if (idStore == NULL) @@ -47,14 +48,15 @@ new_unrhdr(int low, int high, struct mtx* mutex) { void -delete_unrhdr(struct unrhdr* idStore) { +delete_unrhdr(struct unrhdr* idStore) +{ KASSERT(uh != NULL, - ("ID-Store: %s: NULL pointer as argument.", __func__)); + ("ID-Store: %s: NULL pointer as argument.", __func__)); mtx_lock(idStore->storeMutex); KASSERT(uh->idBuffer->root_size == 0, - ("ID-Store: %s: some ids are still in use..", __func__)); + ("ID-Store: %s: some ids are still in use..", __func__)); _delete_unrhdr_buffer_locked(idStore); mtx_unlock(idStore->storeMutex); @@ -65,11 +67,12 @@ delete_unrhdr(struct unrhdr* idStore) { int -alloc_unr(struct unrhdr* idStore) { +alloc_unr(struct unrhdr* idStore) +{ int id; KASSERT(uh != NULL, - ("ID-Store: %s: NULL pointer as argument.", __func__)); + ("ID-Store: %s: NULL pointer as argument.", __func__)); mtx_lock(idStore->storeMutex); id = _alloc_unr_locked(idStore); @@ -80,15 +83,15 @@ alloc_unr(struct unrhdr* idStore) { void -free_unr(struct unrhdr* idStore, u_int identity) { - +free_unr(struct unrhdr* idStore, u_int identity) +{ KASSERT(uh != NULL, - ("ID-Store: %s: NULL pointer as argument.", __func__)); + ("ID-Store: %s: NULL pointer as argument.", __func__)); mtx_lock(idStore->storeMutex); - KASSERT((int32)item - uh->idBias >= 0, ("ID-Store: %s(%p, %u): second " + - "parameter is not in interval.", __func__, uh, item)); + KASSERT((int32)item - uh->idBias >= 0, ("ID-Store: %s(%p, %u): second " + + "parameter is not in interval.", __func__, uh, item)); _free_unr_locked(idStore, identity); diff --git a/src/libs/compat/freebsd_network/unit.h b/src/libs/compat/freebsd_network/unit.h index 5ef7d97d1d..a975675112 100644 --- a/src/libs/compat/freebsd_network/unit.h +++ b/src/libs/compat/freebsd_network/unit.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de + * Copyright 2009 Colin Günther, coling@gmx.de * All Rights Reserved. Distributed under the terms of the MIT License. */ #ifndef UNIT_H_ @@ -21,13 +21,11 @@ struct unrhdr { extern "C" { #endif - status_t _new_unrhdr_buffer(struct unrhdr*, uint32); void _delete_unrhdr_buffer_locked(struct unrhdr*); int _alloc_unr_locked(struct unrhdr*); void _free_unr_locked(struct unrhdr*, u_int); - #ifdef __cplusplus } #endif