more cleanup

This commit is contained in:
Nguyen Anh Quynh
2017-01-10 16:29:47 +08:00
parent c1f39c3db2
commit 7512ff57de
18 changed files with 1 additions and 778 deletions

View File

@ -26,21 +26,8 @@
* Note that nbits should be always a compile time evaluable constant.
* Otherwise many inlines will generate horrible code.
*
* bitmap_zero(dst, nbits) *dst = 0UL
* bitmap_fill(dst, nbits) *dst = ~0UL
* bitmap_copy(dst, src, nbits) *dst = *src
* bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
* bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
* bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2
* bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2)
* bitmap_complement(dst, src, nbits) *dst = ~(*src)
* bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
* bitmap_empty(src, nbits) Are all bits zero in *src?
* bitmap_full(src, nbits) Are all bits set in *src?
* bitmap_set(dst, pos, nbits) Set specified bit area
* bitmap_clear(dst, pos, nbits) Clear specified bit area
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
*/
/*
@ -48,15 +35,6 @@
*
* set_bit(bit, addr) *addr |= bit
* clear_bit(bit, addr) *addr &= ~bit
* change_bit(bit, addr) *addr ^= bit
* test_bit(bit, addr) Is bit set in *addr?
* test_and_set_bit(bit, addr) Set bit and return old value
* test_and_clear_bit(bit, addr) Clear bit and return old value
* test_and_change_bit(bit, addr) Change bit and return old value
* find_first_zero_bit(addr, nbits) Position first zero bit in *addr
* find_first_bit(addr, nbits) Position first set bit in *addr
* find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
* find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
*/
#define BITMAP_LAST_WORD_MASK(nbits) \
@ -68,170 +46,8 @@
#define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)]
#define small_nbits(nbits) \
((nbits) <= BITS_PER_LONG)
int slow_bitmap_empty(const unsigned long *bitmap, long bits);
int slow_bitmap_full(const unsigned long *bitmap, long bits);
int slow_bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, long bits);
void slow_bitmap_complement(unsigned long *dst, const unsigned long *src,
long bits);
void slow_bitmap_shift_right(unsigned long *dst,
const unsigned long *src, int shift, long bits);
void slow_bitmap_shift_left(unsigned long *dst,
const unsigned long *src, int shift, long bits);
int slow_bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, long bits);
void slow_bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, long bits);
void slow_bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, long bits);
int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, long bits);
int slow_bitmap_intersects(const unsigned long *bitmap1,
const unsigned long *bitmap2, long bits);
static inline unsigned long *bitmap_try_new(long nbits)
{
long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
return g_try_malloc0(len);
}
static inline unsigned long *bitmap_new(long nbits)
{
unsigned long *ptr = bitmap_try_new(nbits);
if (ptr == NULL) {
abort();
}
return ptr;
}
static inline void bitmap_zero(unsigned long *dst, long nbits)
{
if (small_nbits(nbits)) {
*dst = 0UL;
} else {
long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
memset(dst, 0, len);
}
}
static inline void bitmap_fill(unsigned long *dst, long nbits)
{
size_t nlongs = BITS_TO_LONGS(nbits);
if (!small_nbits(nbits)) {
long len = (nlongs - 1) * sizeof(unsigned long);
memset(dst, 0xff, len);
}
dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
}
static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
long nbits)
{
if (small_nbits(nbits)) {
*dst = *src;
} else {
long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
memcpy(dst, src, len);
}
}
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, long nbits)
{
if (small_nbits(nbits)) {
return (*dst = *src1 & *src2) != 0;
}
return slow_bitmap_and(dst, src1, src2, nbits);
}
static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, long nbits)
{
if (small_nbits(nbits)) {
*dst = *src1 | *src2;
} else {
slow_bitmap_or(dst, src1, src2, nbits);
}
}
static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, long nbits)
{
if (small_nbits(nbits)) {
*dst = *src1 ^ *src2;
} else {
slow_bitmap_xor(dst, src1, src2, nbits);
}
}
static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, long nbits)
{
if (small_nbits(nbits)) {
return (*dst = *src1 & ~(*src2)) != 0;
}
return slow_bitmap_andnot(dst, src1, src2, nbits);
}
static inline void bitmap_complement(unsigned long *dst,
const unsigned long *src,
long nbits)
{
if (small_nbits(nbits)) {
*dst = ~(*src) & BITMAP_LAST_WORD_MASK(nbits);
} else {
slow_bitmap_complement(dst, src, nbits);
}
}
static inline int bitmap_equal(const unsigned long *src1,
const unsigned long *src2, long nbits)
{
if (small_nbits(nbits)) {
return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
} else {
return slow_bitmap_equal(src1, src2, nbits);
}
}
static inline int bitmap_empty(const unsigned long *src, long nbits)
{
if (small_nbits(nbits)) {
return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
} else {
return slow_bitmap_empty(src, nbits);
}
}
static inline int bitmap_full(const unsigned long *src, long nbits)
{
if (small_nbits(nbits)) {
return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
} else {
return slow_bitmap_full(src, nbits);
}
}
static inline int bitmap_intersects(const unsigned long *src1,
const unsigned long *src2, long nbits)
{
if (small_nbits(nbits)) {
return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
} else {
return slow_bitmap_intersects(src1, src2, nbits);
}
}
void bitmap_set(unsigned long *map, long i, long len);
void bitmap_clear(unsigned long *map, long start, long nr);
unsigned long bitmap_find_next_zero_area(unsigned long *map,
unsigned long size,
unsigned long start,
unsigned long nr,
unsigned long align_mask);
static inline unsigned long *bitmap_zero_extend(unsigned long *old,
long old_nbits, long new_nbits)

View File

@ -48,7 +48,6 @@ typedef enum {
MODULE_INIT_MAX
} module_init_type;
#define block_init(function) module_init(function, MODULE_INIT_BLOCK)
#define machine_init(function) module_init(function, MODULE_INIT_MACHINE)
#define qapi_init(function) module_init(function, MODULE_INIT_QAPI)
#define type_init(function) module_init(function, MODULE_INIT_QOM)

View File

@ -1,35 +0,0 @@
/*
* Commandline option parsing functions
*
* Copyright (c) 2003-2008 Fabrice Bellard
* Copyright (c) 2009 Kevin Wolf <kwolf@redhat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef QEMU_OPTIONS_H
#define QEMU_OPTIONS_H
#include <stdint.h>
#include "qapi/error.h"
void parse_option_size(const char *name, const char *value,
uint64_t *ret, Error **errp);
#endif

View File

@ -168,11 +168,6 @@ void qemu_anon_ram_free(void *ptr, size_t size);
#endif
int qemu_madvise(void *addr, size_t len, int advice);
int qemu_open(const char *name, int flags, ...);
int qemu_close(int fd);
#if defined(__HAIKU__) && defined(__i386__)
#define FMT_pid "%ld"
#elif defined(WIN64)
@ -181,8 +176,6 @@ int qemu_close(int fd);
#define FMT_pid "%d"
#endif
int qemu_create_pidfile(const char *filename);
#ifdef _WIN32
static inline void qemu_timersub(const struct timeval *val1,
const struct timeval *val2,

View File

@ -1,65 +0,0 @@
/*
* Seqlock implementation for QEMU
*
* Copyright Red Hat, Inc. 2013
*
* Author:
* Paolo Bonzini <pbonzini@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*
*/
#ifndef QEMU_SEQLOCK_H
#define QEMU_SEQLOCK_H 1
#include <qemu/atomic.h>
#include <qemu/thread.h>
typedef struct QemuSeqLock QemuSeqLock;
struct QemuSeqLock {
QemuMutex *mutex;
unsigned sequence;
};
static inline void seqlock_init(QemuSeqLock *sl, QemuMutex *mutex)
{
sl->mutex = mutex;
sl->sequence = 0;
}
/* Lock out other writers and update the count. */
static inline void seqlock_write_lock(QemuSeqLock *sl)
{
if (sl->mutex) {
qemu_mutex_lock(sl->mutex);
}
++sl->sequence;
/* Write sequence before updating other fields. */
smp_wmb();
}
static inline void seqlock_write_unlock(QemuSeqLock *sl)
{
/* Write other fields before finalizing sequence. */
smp_wmb();
++sl->sequence;
if (sl->mutex) {
qemu_mutex_unlock(sl->mutex);
}
}
static inline unsigned seqlock_read_begin(QemuSeqLock *sl)
{
/* Always fail if a write is in progress. */
unsigned ret = sl->sequence & ~1;
/* Read sequence before reading other fields. */
smp_rmb();
return ret;
}
#endif

View File

@ -106,147 +106,6 @@ static inline int64_t qemu_clock_get_us(QEMUClockType type)
return qemu_clock_get_ns(type) / SCALE_US;
}
/**
* qemu_clock_has_timers:
* @type: the clock type
*
* Determines whether a clock's default timer list
* has timers attached
*
* Note that this function should not be used when other threads also access
* the timer list. The return value may be outdated by the time it is acted
* upon.
*
* Returns: true if the clock's default timer list
* has timers attached
*/
bool qemu_clock_has_timers(QEMUClockType type);
/**
* qemu_clock_expired:
* @type: the clock type
*
* Determines whether a clock's default timer list
* has an expired clock.
*
* Returns: true if the clock's default timer list has
* an expired timer
*/
bool qemu_clock_expired(QEMUClockType type);
/**
* qemu_clock_use_for_deadline:
* @type: the clock type
*
* Determine whether a clock should be used for deadline
* calculations. Some clocks, for instance vm_clock with
* use_icount set, do not count in nanoseconds. Such clocks
* are not used for deadline calculations, and are presumed
* to interrupt any poll using qemu_notify/aio_notify
* etc.
*
* Returns: true if the clock runs in nanoseconds and
* should be used for a deadline.
*/
bool qemu_clock_use_for_deadline(QEMUClockType type);
/**
* qemu_clock_deadline_ns_all:
* @type: the clock type
*
* Calculate the deadline across all timer lists associated
* with a clock (as opposed to just the default one)
* in nanoseconds, or -1 if no timer is set to expire.
*
* Returns: time until expiry in nanoseconds or -1
*/
int64_t qemu_clock_deadline_ns_all(QEMUClockType type);
/**
* qemu_clock_get_main_loop_timerlist:
* @type: the clock type
*
* Return the default timer list assocatiated with a clock.
*
* Returns: the default timer list
*/
QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClockType type);
/**
* qemu_clock_nofify:
* @type: the clock type
*
* Call the notifier callback connected with the default timer
* list linked to the clock, or qemu_notify() if none.
*/
void qemu_clock_notify(QEMUClockType type);
/**
* qemu_clock_enable:
* @type: the clock type
* @enabled: true to enable, false to disable
*
* Enable or disable a clock
* Disabling the clock will wait for related timerlists to stop
* executing qemu_run_timers. Thus, this functions should not
* be used from the callback of a timer that is based on @clock.
* Doing so would cause a deadlock.
*
* Caller should hold BQL.
*/
void qemu_clock_enable(QEMUClockType type, bool enabled);
/**
* qemu_clock_warp:
* @type: the clock type
*
* Warp a clock to a new value
*/
void qemu_clock_warp(QEMUClockType type);
/**
* qemu_clock_register_reset_notifier:
* @type: the clock type
* @notifier: the notifier function
*
* Register a notifier function to call when the clock
* concerned is reset.
*/
void qemu_clock_register_reset_notifier(QEMUClockType type,
Notifier *notifier);
/**
* qemu_clock_unregister_reset_notifier:
* @type: the clock type
* @notifier: the notifier function
*
* Unregister a notifier function to call when the clock
* concerned is reset.
*/
void qemu_clock_unregister_reset_notifier(QEMUClockType type,
Notifier *notifier);
/**
* qemu_clock_run_timers:
* @type: clock on which to operate
*
* Run all the timers associated with the default timer list
* of a clock.
*
* Returns: true if any timer ran.
*/
bool qemu_clock_run_timers(QEMUClockType type);
/**
* qemu_clock_run_all_timers:
*
* Run all the timers associated with the default timer list
* of every clock.
*
* Returns: true if any timer ran.
*/
bool qemu_clock_run_all_timers(void);
/*
* QEMUTimerList
*/