From 1d7ad5dbbc29efe58171b1023ab0df09eb2815bf Mon Sep 17 00:00:00 2001 From: Zhou Wenjian Date: Fri, 18 Mar 2016 10:35:35 +0800 Subject: [PATCH] increment --- makedumpfile.c | 107 ++++++++++++++++++++++++++++++++++++++++++--------------- makedumpfile.h | 12 +++++-- 2 files changed, 89 insertions(+), 30 deletions(-) diff --git a/makedumpfile.c b/makedumpfile.c index 2b0864a..a304a61 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -3477,6 +3477,42 @@ calibrate_machdep_info(void) } int +initial_parallel_area(int page_data_buf_size) +{ + int i, j; + struct page_flag *current; + info->page_data_buf = info->parallel_area; + void *page_data_buf = info->parallel_area + sizeof(struct page_data) * info->num_buffers; + void *page_flag_list = page_data_buf + page_data_buf_size * info->num_buffers; + + for (i = 0; i < info->num_buffers; i++) { + info->page_data_buf[i].buf = page_data_buf + page_data_buf_size * i; + } + + + if ((info->page_flag_list = malloc(sizeof(struct page_flag_list) * info->num_threads)) + == NULL) { + MSG("Can't allocate memory for page_flag_buf. %s\n", + strerror(errno)); + return FALSE; + } + + for (i = 0; i < info->num_threads; i++) { + info->page_flag_list[i].header = page_flag_list + sizeof(struct page_flag) * info->num_buffers * i; + info->page_flag_list[i].current = 0; + /* + current = info->page_flag_buf[i]; + for (j = 1; j < info->num_buffers; j++) { + current->next = current + sizeof(struct page_flag); + current = current->next; + } + current->next = info->page_flag_buf[i]; +*/ + } + +} + +int initial_for_parallel() { unsigned long len_buf_out; @@ -3575,9 +3611,15 @@ initial_for_parallel() DEBUG_MSG("Number of struct page_data for produce/consume: %d\n", info->num_buffers); - /* - * allocate memory for page_data - */ + if ((info->parallel_area = calloc(info->num_buffers, sizeof(struct page_data)+page_data_buf_size + sizeof(struct page_flag)*info->num_threads)) + ==NULL) { + MSG("Can't allocate memory for page_data_buf. %s\n", + strerror(errno)); + return FALSE; + } + + initial_parallel_area(page_data_buf_size); +/* if ((info->page_data_buf = malloc(sizeof(struct page_data) * info->num_buffers)) == NULL) { MSG("Can't allocate memory for page_data_buf. %s\n", @@ -3594,9 +3636,6 @@ initial_for_parallel() } } - /* - * initial page_flag for each thread - */ if ((info->page_flag_buf = malloc(sizeof(void *) * info->num_threads)) == NULL) { MSG("Can't allocate memory for page_flag_buf. %s\n", @@ -3623,7 +3662,7 @@ initial_for_parallel() } current->next = info->page_flag_buf[i]; } - +*/ /* * initial fd_memory for threads */ @@ -3685,6 +3724,15 @@ free_for_parallel() if (info->kdump_thread_args != NULL) free(info->kdump_thread_args); + if (info->page_flag_list != NULL) { + free(info->page_flag_list); + } + + if (info->parallel_area != NULL) { + free(info->parallel_area); + } + +/* if (info->page_data_buf != NULL) { for (i = 0; i < info->num_buffers; i++) { if (info->page_data_buf[i].buf != NULL) @@ -3705,7 +3753,7 @@ free_for_parallel() } free(info->page_flag_buf); } - +*/ if (info->parallel_info == NULL) return; @@ -7122,12 +7170,14 @@ int finalize_zlib(z_stream *stream) return err; } +#define CURRENT_FLAG page_flag_header[current_page_flag] void * kdump_thread_function_cyclic(void *arg) { void *retval = PTHREAD_FAIL; struct thread_args *kdump_thread_args = (struct thread_args *)arg; volatile struct page_data *page_data_buf = kdump_thread_args->page_data_buf; - volatile struct page_flag *page_flag_buf = kdump_thread_args->page_flag_buf; + struct page_flag *page_flag_header = kdump_thread_args->page_flag_list->header; + int current_page_flag = kdump_thread_args->page_flag_list->current; struct cycle *cycle = kdump_thread_args->cycle; mdf_pfn_t pfn = cycle->start_pfn; int index = kdump_thread_args->thread_num; @@ -7193,7 +7243,7 @@ kdump_thread_function_cyclic(void *arg) { while (buf_ready == FALSE) { pthread_testcancel(); - if (page_flag_buf->ready == FLAG_READY) + if (CURRENT_FLAG.ready == FLAG_READY) continue; /* get next dumpable pfn */ @@ -7208,8 +7258,8 @@ kdump_thread_function_cyclic(void *arg) { } info->current_pfn = pfn + 1; - page_flag_buf->pfn = pfn; - page_flag_buf->ready = FLAG_FILLING; + CURRENT_FLAG.pfn = pfn; + CURRENT_FLAG.ready = FLAG_FILLING; pthread_mutex_unlock(&info->current_pfn_mutex); sem_post(&info->page_flag_buf_sem); @@ -7230,11 +7280,11 @@ kdump_thread_function_cyclic(void *arg) { if ((info->dump_level & DL_EXCLUDE_ZERO) && is_zero_page(buf, info->page_size)) { - page_flag_buf->zero = TRUE; + CURRENT_FLAG.zero = TRUE; goto next; } - page_flag_buf->zero = FALSE; + CURRENT_FLAG.zero = FALSE; /* * Compress the page data. @@ -7285,11 +7335,11 @@ kdump_thread_function_cyclic(void *arg) { page_data_buf[index].size = info->page_size; memcpy(page_data_buf[index].buf, buf, info->page_size); } - page_flag_buf->index = index; + CURRENT_FLAG.index = index; buf_ready = TRUE; next: - page_flag_buf->ready = FLAG_READY; - page_flag_buf = page_flag_buf->next; + CURRENT_FLAG.ready = FLAG_READY; + current_page_flag = (current_page_flag + 1) % info->num_buffers; } } @@ -7306,6 +7356,8 @@ fail: pthread_exit(retval); } +#define CURRENT_PAGE_FLAG(i) (info->page_flag_list[i].header)[info->page_flag_list[i].current] + int write_kdump_pages_parallel_cyclic(struct cache_data *cd_header, struct cache_data *cd_page, @@ -7379,7 +7431,7 @@ write_kdump_pages_parallel_cyclic(struct cache_data *cd_header, kdump_thread_args[i].thread_num = i; kdump_thread_args[i].len_buf_out = len_buf_out; kdump_thread_args[i].page_data_buf = page_data_buf; - kdump_thread_args[i].page_flag_buf = info->page_flag_buf[i]; + kdump_thread_args[i].page_flag_list = &(info->page_flag_list[i]); kdump_thread_args[i].cycle = cycle; res = pthread_create(threads[i], NULL, @@ -7418,15 +7470,15 @@ write_kdump_pages_parallel_cyclic(struct cache_data *cd_header, * current_pfn is used for recording the value of pfn when checking the pfn. */ for (i = 0; i < info->num_threads; i++) { - if (info->page_flag_buf[i]->ready == FLAG_UNUSED) + if (CURRENT_PAGE_FLAG(i).ready == FLAG_UNUSED) continue; - temp_pfn = info->page_flag_buf[i]->pfn; + temp_pfn = CURRENT_PAGE_FLAG(i).pfn; /* * count how many threads have reached the end. */ if (temp_pfn >= end_pfn) { - info->page_flag_buf[i]->ready = FLAG_UNUSED; + CURRENT_PAGE_FLAG(i).ready = FLAG_UNUSED; end_count++; continue; } @@ -7449,7 +7501,7 @@ write_kdump_pages_parallel_cyclic(struct cache_data *cd_header, * If the page_flag_buf is not ready, the pfn recorded may be changed. * So we should recheck. */ - if (info->page_flag_buf[consuming]->ready != FLAG_READY) { + if (CURRENT_PAGE_FLAG(consuming).ready != FLAG_READY) { gettimeofday(&new, NULL); if (new.tv_sec - last.tv_sec > WAIT_TIME) { ERRMSG("Can't get data of pfn.\n"); @@ -7458,7 +7510,7 @@ write_kdump_pages_parallel_cyclic(struct cache_data *cd_header, continue; } - if (current_pfn == info->page_flag_buf[consuming]->pfn) + if (current_pfn == CURRENT_PAGE_FLAG(consuming).pfn) break; } @@ -7468,12 +7520,12 @@ write_kdump_pages_parallel_cyclic(struct cache_data *cd_header, num_dumped++; - if (info->page_flag_buf[consuming]->zero == TRUE) { + if (CURRENT_PAGE_FLAG(consuming).zero == TRUE) { if (!write_cache(cd_header, pd_zero, sizeof(page_desc_t))) goto out; pfn_zero++; } else { - index = info->page_flag_buf[consuming]->index; + index = CURRENT_PAGE_FLAG(consuming).index; pd.flags = page_data_buf[index].flags; pd.size = page_data_buf[index].size; pd.page_flags = 0; @@ -7491,8 +7543,9 @@ write_kdump_pages_parallel_cyclic(struct cache_data *cd_header, goto out; page_data_buf[index].used = FALSE; } - info->page_flag_buf[consuming]->ready = FLAG_UNUSED; - info->page_flag_buf[consuming] = info->page_flag_buf[consuming]->next; + CURRENT_PAGE_FLAG(consuming).ready = FLAG_UNUSED; + info->page_flag_list[consuming].current += 1; + info->page_flag_list[consuming].current %= info->num_buffers; } finish: ret = TRUE; diff --git a/makedumpfile.h b/makedumpfile.h index 4b315c0..8c4bc1a 100644 --- a/makedumpfile.h +++ b/makedumpfile.h @@ -996,7 +996,12 @@ struct page_flag { char zero; char ready; short index; - struct page_flag *next; +// struct page_flag *next; +}; + +struct page_flag_list { + struct page_flag *header; + int current; }; struct page_data @@ -1012,7 +1017,7 @@ struct thread_args { unsigned long len_buf_out; struct cycle *cycle; struct page_data *page_data_buf; - struct page_flag *page_flag_buf; + struct page_flag_list *page_flag_list; }; /* @@ -1298,10 +1303,11 @@ struct DumpInfo { */ int num_threads; int num_buffers; + void *parallel_area; pthread_t **threads; struct thread_args *kdump_thread_args; struct page_data *page_data_buf; - struct page_flag **page_flag_buf; + struct page_flag_list *page_flag_list; sem_t page_flag_buf_sem; pthread_rwlock_t usemmap_rwlock; mdf_pfn_t current_pfn; -- 1.8.3.1