[PATCH 1/2] LOOP: make the item type applicable to jobs too.
by Angus Salkeld
Mainly for diagnostics
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/loop_int.h | 8 ++++++++
lib/loop_job.c | 1 +
lib/loop_poll.c | 35 +++++++++++++----------------------
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/lib/loop_int.h b/lib/loop_int.h
index be98d31..84c18cd 100644
--- a/lib/loop_int.h
+++ b/lib/loop_int.h
@@ -27,10 +27,18 @@
struct qb_loop;
struct qb_loop_item;
+enum qb_loop_type {
+ QB_LOOP_FD,
+ QB_LOOP_JOB,
+ QB_LOOP_TIMER,
+ QB_LOOP_SIG,
+};
+
struct qb_loop_item {
struct qb_list_head list;
struct qb_loop_source *source;
void *user_data;
+ enum qb_loop_type type;
};
struct qb_loop_level {
diff --git a/lib/loop_job.c b/lib/loop_job.c
index 123d1af..32aa7b9 100644
--- a/lib/loop_job.c
+++ b/lib/loop_job.c
@@ -107,6 +107,7 @@ qb_loop_job_add(struct qb_loop *l,
job->dispatch_fn = dispatch_fn;
job->item.user_data = data;
job->item.source = l->job_source;
+ job->item.type = QB_LOOP_JOB;
qb_list_init(&job->item.list);
qb_list_add_tail(&job->item.list, &l->level[p].wait_head);
diff --git a/lib/loop_poll.c b/lib/loop_poll.c
index 7a03156..ae4286c 100644
--- a/lib/loop_poll.c
+++ b/lib/loop_poll.c
@@ -56,14 +56,6 @@ int epoll_create1(int flags);
/* logs, std(in|out|err), pipe */
#define POLL_FDS_USED_MISC 50
-enum qb_poll_type {
- QB_UNKNOWN,
- QB_JOB,
- QB_POLL,
- QB_SIGNAL,
- QB_TIMER,
-};
-
struct qb_poll_entry;
typedef int32_t(*qb_poll_add_to_jobs_fn) (struct qb_loop * l,
@@ -71,7 +63,6 @@ typedef int32_t(*qb_poll_add_to_jobs_fn) (struct qb_loop * l,
struct qb_poll_entry {
struct qb_loop_item item;
- enum qb_poll_type type;
qb_loop_poll_dispatch_fn poll_dispatch_fn;
qb_loop_timer_dispatch_fn timer_dispatch_fn;
enum qb_loop_priority p;
@@ -204,7 +195,7 @@ _poll_dispatch_and_take_back_(struct qb_loop_item *item,
assert(pe->state == QB_POLL_ENTRY_JOBLIST);
- if (pe->type == QB_POLL) {
+ if (pe->item.type == QB_LOOP_FD) {
res = pe->poll_dispatch_fn(pe->ufd.fd,
pe->ufd.revents,
pe->item.user_data);
@@ -214,12 +205,12 @@ _poll_dispatch_and_take_back_(struct qb_loop_item *item,
pe->state = QB_POLL_ENTRY_ACTIVE;
pe->ufd.revents = 0;
}
- } else if (pe->type == QB_TIMER) {
+ } else if (pe->item.type == QB_LOOP_TIMER) {
_poll_entry_mark_deleted_(pe);
pe->timer_dispatch_fn(pe->item.user_data);
} else {
qb_util_log(LOG_WARNING,
- "poll entry of unknown type:%d state:%d", pe->type,
+ "poll entry of unknown type:%d state:%d", pe->item.type,
pe->state);
return;
}
@@ -234,14 +225,14 @@ _poll_dispatch_and_take_back_(struct qb_loop_item *item,
log_warn = QB_TRUE;
}
- if (log_warn && pe->type == QB_POLL) {
+ if (log_warn && pe->item.type == QB_LOOP_FD) {
qb_util_log(LOG_INFO,
"[fd:%d] dispatch:%p runs:%d duration:%d ms",
pe->ufd.fd, pe->poll_dispatch_fn,
pe->runs,
(int32_t) ((stop -
start) / QB_TIME_NS_IN_MSEC));
- } else if (log_warn && pe->type == QB_TIMER) {
+ } else if (log_warn && pe->item.type == QB_LOOP_TIMER) {
qb_util_log(LOG_INFO,
"[timer] dispatch:%p runs:%d duration:%d ms",
pe->timer_dispatch_fn,
@@ -552,7 +543,7 @@ _poll_add_(struct qb_loop *l,
static int32_t
_qb_poll_add_to_jobs_(struct qb_loop *l, struct qb_poll_entry *pe)
{
- assert(pe->type == QB_POLL);
+ assert(pe->item.type == QB_LOOP_FD);
qb_loop_level_item_add(&l->level[pe->p], &pe->item);
pe->state = QB_POLL_ENTRY_JOBLIST;
return 1;
@@ -575,7 +566,7 @@ qb_loop_poll_add(struct qb_loop * l,
new_size = ((struct qb_poll_source *)l->fd_source)->poll_entry_count;
pe->poll_dispatch_fn = dispatch_fn;
- pe->type = QB_POLL;
+ pe->item.type = QB_LOOP_FD;
pe->add_to_jobs = _qb_poll_add_to_jobs_;
if (new_size > size) {
@@ -644,7 +635,7 @@ qb_loop_poll_del(struct qb_loop * l, int32_t fd)
for (i = 0; i < s->poll_entry_count; i++) {
assert(qb_array_index(s->poll_entries, i, (void **)&pe) == 0);
- if (pe->ufd.fd != fd || pe->type != QB_POLL) {
+ if (pe->ufd.fd != fd || pe->item.type != QB_LOOP_FD) {
continue;
}
if (pe->state == QB_POLL_ENTRY_DELETED ||
@@ -678,7 +669,7 @@ _qb_timer_add_to_jobs_(struct qb_loop *l, struct qb_poll_entry *pe)
uint64_t expired = 0;
ssize_t bytes = 0;
- assert(pe->type == QB_TIMER);
+ assert(pe->item.type == QB_LOOP_TIMER);
if (pe->ufd.revents == POLLIN) {
bytes = read(pe->ufd.fd, &expired, sizeof(expired));
if (bytes != sizeof(expired)) {
@@ -763,7 +754,7 @@ qb_loop_timer_add(struct qb_loop *l,
new_size, fd);
}
pe->timer_dispatch_fn = timer_fn;
- pe->type = QB_TIMER;
+ pe->item.type = QB_LOOP_TIMER;
pe->add_to_jobs = _qb_timer_add_to_jobs_;
if (timer_handle_out) {
@@ -793,10 +784,10 @@ qb_loop_timer_del(struct qb_loop * l, qb_loop_timer_handle th)
return res;
}
- if (pe->type != QB_TIMER) {
+ if (pe->item.type != QB_LOOP_TIMER) {
qb_util_log(LOG_WARNING,
"trying to delete timer but handle points to type:%d",
- pe->type);
+ pe->item.type);
return -EINVAL;
}
if (pe->state == QB_POLL_ENTRY_DELETED) {
@@ -935,7 +926,7 @@ qb_loop_signals_create(struct qb_loop *l)
pipe_fds[0], POLLIN, NULL, &pe);
if (res == 0) {
pe->poll_dispatch_fn = NULL;
- pe->type = QB_SIGNAL;
+ pe->item.type = QB_LOOP_SIG;
pe->add_to_jobs = _qb_signal_add_to_jobs_;
} else {
qb_util_perror(LOG_ERR, "Can't smoke pipe");
--
1.7.7.6
12 years, 2 months
[PATCH 1/3] LOOP: prevent jobs from consuming too much cpu.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/loop.c | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/lib/loop.c b/lib/loop.c
index 142e7eb..c0f6f33 100644
--- a/lib/loop.c
+++ b/lib/loop.c
@@ -119,6 +119,8 @@ qb_loop_run(struct qb_loop *l)
int32_t p;
int32_t p_stop = QB_LOOP_LOW;
int32_t todo = 0;
+ int32_t job_todo;
+ int32_t timer_todo;
int32_t ms_timeout;
l->stop_requested = QB_FALSE;
@@ -131,13 +133,28 @@ qb_loop_run(struct qb_loop *l)
}
if (l->job_source && l->job_source->poll) {
- todo += l->job_source->poll(l->job_source, 0);
+ job_todo = l->job_source->poll(l->job_source, 0);
+ } else {
+ job_todo = 0;
}
if (l->timer_source && l->timer_source->poll) {
- todo += l->timer_source->poll(l->timer_source, 0);
+ timer_todo = l->timer_source->poll(l->timer_source, 0);
+ } else {
+ timer_todo = 0;
}
- if (todo > 0) {
+ if (todo > 0 || timer_todo > 0) {
+ /*
+ * if there are old todos or timer todos then don't wait.
+ */
ms_timeout = 0;
+ } else if (job_todo > 0) {
+ todo = 0;
+ /*
+ * if we only have jobs to do (not timers or old todos)
+ * then set a non-zero timeout. Jobs can spin out of
+ * control if someone keeps adding them.
+ */
+ ms_timeout = 50;
} else {
todo = 0;
if (l->timer_source) {
--
1.7.7.6
12 years, 2 months
[PATCH 1/5] Add clang-analyzer check
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
check | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/check b/check
index 0fa81bb..24b3f0d 100755
--- a/check
+++ b/check
@@ -21,6 +21,7 @@ help_all() {
echo " rpm Run rpmlint"
echo " mock Test doing a mock build"
echo " coverity Run coverity"
+ echo " clang Run clang-analyze"
echo " abi Check abi compatibility"
echo " api_sanity api sanity test"
echo
@@ -169,6 +170,20 @@ check_coverity() {
cov-format-errors --dir cov
}
+check_clang() {
+ if [ ! -f /usr/lib64/clang-analyzer/scan-build/ccc-analyzer ]
+ then
+ echo try installing clang-analyze
+ exit 1
+ fi
+ make clean
+
+ ./configure \
+ CC=/usr/lib64/clang-analyzer/scan-build/ccc-analyzer \
+ CXX=/usr/lib64/clang-analyzer/scan-build/c++-analyzer
+ make check
+}
+
check_abi() {
ver1=$1
ver2=$2
@@ -271,6 +286,9 @@ case $command in
coverity)
check_coverity
;;
+ clang)
+ check_clang
+ ;;
abi)
check_abi $args
;;
--
1.7.7.6
12 years, 2 months