all: reduce brick list traversals

This commit is contained in:
Thomas Schoebel-Theuer 2020-03-07 07:07:52 +01:00
parent 343670b52d
commit 19d20567fd
3 changed files with 36 additions and 21 deletions

View File

@ -6268,6 +6268,14 @@ static int _main_thread(void *data)
while (mars_global->global_power.button ||
!list_empty(&mars_global->brick_anchor)) {
static const struct mars_brick_type *type_list[] = {
(void *)&copy_brick_type,
(void *)&client_brick_type,
(void *)&aio_brick_type,
(void *)&sio_brick_type,
(void *)&bio_brick_type,
NULL
};
struct list_head *tmp;
int trigger_mode;
int status;
@ -6336,27 +6344,19 @@ static int _main_thread(void *data)
if (!mars_global->global_power.button) {
status = mars_kill_brick_when_possible(mars_global,
(void*)&copy_brick_type, true);
MARS_DBG("kill copy bricks (when possible) = %d\n", status);
type_list,
true);
} else {
status = mars_kill_brick_when_possible(mars_global,
type_list + 1,
true);
}
MARS_DBG("kill any bricks (when possible) = %d\n", status);
status = mars_kill_brick_when_possible(mars_global,
NULL, false);
MARS_DBG("kill main bricks (when possible) = %d\n", status);
status = mars_kill_brick_when_possible(mars_global,
(void*)&client_brick_type, true);
MARS_DBG("kill client bricks (when possible) = %d\n", status);
status = mars_kill_brick_when_possible(mars_global,
(void*)&aio_brick_type, true);
MARS_DBG("kill aio bricks (when possible) = %d\n", status);
status = mars_kill_brick_when_possible(mars_global,
(void*)&sio_brick_type, true);
MARS_DBG("kill sio bricks (when possible) = %d\n", status);
status = mars_kill_brick_when_possible(mars_global,
(void*)&bio_brick_type, true);
MARS_DBG("kill bio bricks (when possible) = %d\n", status);
if ((long long)jiffies + mars_rollover_interval * HZ >= last_rollover) {
last_rollover = jiffies;
rollover_all();

View File

@ -170,7 +170,7 @@ extern int mars_free_brick(struct mars_brick *brick);
extern int mars_kill_brick(struct mars_brick *brick);
extern int mars_kill_brick_all(struct mars_global *global, struct list_head *anchor, bool use_dent_link);
extern int mars_kill_brick_when_possible(struct mars_global *global,
const struct mars_brick_type *type,
const struct mars_brick_type *type_list[],
bool even_on);
// mid-level brick instantiation (identity is based on path strings)

View File

@ -2628,7 +2628,7 @@ done:
EXPORT_SYMBOL_GPL(mars_kill_brick_all);
int mars_kill_brick_when_possible(struct mars_global *global,
const struct mars_brick_type *type,
const struct mars_brick_type *type_list[],
bool even_on)
{
struct list_head *anchor = &global->brick_anchor;
@ -2647,10 +2647,6 @@ restart:
brick = container_of(tmp, struct mars_brick, global_brick_link);
// only kill the right brick types
if (type && brick->type != type) {
continue;
}
// only kill marked bricks
if (!brick->killme) {
continue;
@ -2662,6 +2658,25 @@ restart:
if (!even_on && (brick->power.button || !brick->power.led_off)) {
continue;
}
/* Only kill the right brick types
*/
if (type_list) {
int index = 0;
const struct mars_brick_type *this_type = type_list[index++];
bool matches = false;
while (this_type) {
if (this_type == brick->type) {
matches = true;
break;
}
this_type = type_list[index++];
}
if (!matches)
continue;
}
// only kill bricks which have no resources allocated
count = atomic_read(&brick->mref_object_layout.alloc_count);
if (count > 0) {