/* * Copyright (c) 2017 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// lock the mutex for queue access #if CONFIG_MULTITHREAD
pthread_mutex_lock(mutex_handle); #endif
next = job_queue_hdl->next; if (next != NULL) {
JobQueue *job_queue = (JobQueue *)next;
job_info = &job_queue->job_info; // Update the next job in the queue
job_queue_hdl->next = job_queue->next;
job_queue_hdl->num_jobs_acquired++;
}
// Allocate memory that is large enough for all row_mt stages. First pass // uses 16x16 block size.
jobs_per_tile_col = VPXMAX(cm->mb_rows, sb_rows); // Calculate the total number of jobs
total_jobs = jobs_per_tile_col * tile_cols;
#if CONFIG_MULTITHREAD // Create mutex for each tile for (tile_col = 0; tile_col < tile_cols; tile_col++) {
RowMTInfo *row_mt_info = &multi_thread_ctxt->row_mt_info[tile_col];
pthread_mutex_init(&row_mt_info->job_mutex, NULL);
} #endif
// Allocate memory for row based multi-threading for (tile_col = 0; tile_col < tile_cols; tile_col++) {
TileDataEnc *this_tile = &cpi->tile_data[tile_col];
vp9_row_mt_sync_mem_alloc(&this_tile->row_mt_sync, cm, jobs_per_tile_col);
}
// Assign the sync pointer of tile row zero for every tile row > 0 for (tile_row = 1; tile_row < tile_rows; tile_row++) { for (tile_col = 0; tile_col < tile_cols; tile_col++) {
TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col];
TileDataEnc *this_col_tile = &cpi->tile_data[tile_col];
this_tile->row_mt_sync = this_col_tile->row_mt_sync;
}
}
// Calculate the number of vertical units in the given tile row for (tile_row = 0; tile_row < tile_rows; tile_row++) {
TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols];
TileInfo *tile_info = &this_tile->tile_info;
multi_thread_ctxt->num_tile_vert_sbs[tile_row] =
get_num_vert_units(*tile_info, MI_BLOCK_SIZE_LOG2);
}
}
void vp9_row_mt_mem_dealloc(VP9_COMP *cpi) {
MultiThreadHandle *multi_thread_ctxt = &cpi->multi_thread_ctxt; int tile_col; #if CONFIG_MULTITHREAD int tile_row; #endif
// Deallocate memory for job queue if (multi_thread_ctxt->job_queue) {
vpx_free(multi_thread_ctxt->job_queue);
multi_thread_ctxt->job_queue = NULL;
}
#if CONFIG_MULTITHREAD // Destroy mutex for each tile for (tile_col = 0; tile_col < multi_thread_ctxt->allocated_tile_cols;
tile_col++) {
RowMTInfo *row_mt_info = &multi_thread_ctxt->row_mt_info[tile_col];
pthread_mutex_destroy(&row_mt_info->job_mutex);
} #endif
for (i = 0; i < tile_cols; i++) {
TileDataEnc *this_tile = &cpi->tile_data[i]; int jobs_per_tile_col = cpi->oxcf.pass == 1 ? cm->mb_rows : sb_rows;
// Initialize cur_col to -1 for all rows.
memset(this_tile->row_mt_sync.cur_col, -1, sizeof(*this_tile->row_mt_sync.cur_col) * jobs_per_tile_col);
vp9_zero(this_tile->fp_data);
this_tile->fp_data.image_data_start_row = INVALID_ROW;
}
}
void vp9_assign_tile_to_thread(MultiThreadHandle *multi_thread_ctxt, int tile_cols, int num_workers) { int tile_id = 0; int i;
// Allocating the threads for the tiles for (i = 0; i < num_workers; i++) {
multi_thread_ctxt->thread_id_to_tile_id[i] = tile_id++; if (tile_id == tile_cols) tile_id = 0;
}
}
int vp9_get_job_queue_status(MultiThreadHandle *multi_thread_ctxt, int cur_tile_id) {
RowMTInfo *row_mt_info;
JobQueueHandle *job_queue_hndl; #if CONFIG_MULTITHREAD
pthread_mutex_t *mutex; #endif int num_jobs_remaining;
int vp9_get_tiles_proc_status(MultiThreadHandle *multi_thread_ctxt, int *tile_completion_status, int *cur_tile_id, int tile_cols) { int tile_col; int tile_id = -1; // Stores the tile ID with minimum proc done int max_num_jobs_remaining = 0; int num_jobs_remaining;
// Mark the completion to avoid check in the loop
tile_completion_status[*cur_tile_id] = 1; // Check for the status of all the tiles for (tile_col = 0; tile_col < tile_cols; tile_col++) { if (tile_completion_status[tile_col] == 0) {
num_jobs_remaining =
vp9_get_job_queue_status(multi_thread_ctxt, tile_col); // Mark the completion to avoid checks during future switches across tiles if (num_jobs_remaining == 0) tile_completion_status[tile_col] = 1; if (num_jobs_remaining > max_num_jobs_remaining) {
max_num_jobs_remaining = num_jobs_remaining;
tile_id = tile_col;
}
}
}
if (-1 == tile_id) { return 1;
} else { // Update the cur ID to the next tile ID that will be processed, // which will be the least processed tile
*cur_tile_id = tile_id; return 0;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.