bool servers_init(bool dont_read_servers_table)
{
  THD  *thd;
  bool return_val= FALSE;
  DBUG_ENTER("servers_init");

  /* init the mutex */
  if (my_rwlock_init(&THR_LOCK_servers, NULL))
    DBUG_RETURN(TRUE);

  /* initialise our servers cache */
  if (hash_init(&servers_cache, system_charset_info, 32, 0, 0,
                (hash_get_key) servers_cache_get_key, 0, 0))
  {
    return_val= TRUE; /* we failed, out of memory? */
    goto end;
  }

  /* Initialize the mem root for data */
  init_alloc_root(&mem, ACL_ALLOC_BLOCK_SIZE, 0);

  if (dont_read_servers_table)
    goto end;

  /*
    To be able to run this from boot, we allocate a temporary THD
  */
  if (!(thd=new THD))
    DBUG_RETURN(TRUE);
  thd->thread_stack= (char*) &thd;
  thd->store_globals();
  lex_start(thd);
  /*
    It is safe to call servers_reload() since servers_* arrays and hashes which
    will be freed there are global static objects and thus are initialized
    by zeros at startup.
  */
  return_val= servers_reload(thd);
  delete thd;
  /* Remember that we don't have a THD */
  my_pthread_setspecific_ptr(THR_THD,  0);

end:
  DBUG_RETURN(return_val);
}
Ejemplo n.º 2
0
static TDHS_INLINE THD* init_THD(char* db, const void *stack_bottom,
                                 bool need_write) {
    THD *thd = NULL;
    my_thread_init();
    thd = new THD;
    if (thd == NULL) {
        my_thread_end();
        return NULL;
    }
    thd->thread_stack = (char*) stack_bottom;
    easy_debug_log("TDHS:thread_stack = %p sizeof(THD)=%zu sizeof(mtx)=%zu ",
                   thd->thread_stack, sizeof(THD), sizeof(LOCK_thread_count));
    thd->store_globals();
    thd->system_thread = static_cast<enum_thread_type>(1 << 30UL);
    const NET v = { 0 };
    thd->net = v;
    if (need_write) {
        //for write
#if MYSQL_VERSION_ID >= 50505
        thd->variables.option_bits |= OPTION_BIN_LOG;
#else
        thd->options |= OPTION_BIN_LOG;
#endif
    }
    //for db
    safeFree(thd->db);
    thd->db = db;
    my_pthread_setspecific_ptr(THR_THD, thd);

    tdhs_mysql_mutex_lock(&LOCK_thread_count);
    thd->thread_id = thread_id++;
    threads.append(thd);
    ++thread_count;
    tdhs_mysql_mutex_unlock(&LOCK_thread_count);
    return thd;
}
Ejemplo n.º 3
0
extern "C" double gsum(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) 
{
	DBUG_ENTER("udf_sum::gsum");

	double* h_in;
	double* h_out;
	double* d_in;
	double* d_out;
	unsigned int index = 0;

	cudaHostAlloc((void**)&h_in, MAXIMUM_ELEMENTS_IN_CACHE*sizeof(double), cudaHostAllocWriteCombined | cudaHostAllocMapped );
	CUDA_CHECK_ERRORS("cudaHostAlloc -> h_in");
	cudaHostAlloc((void**)&h_out, CUDA_BLOCK_SIZE*sizeof(double), cudaHostAllocWriteCombined | cudaHostAllocMapped );
	CUDA_CHECK_ERRORS("cudaHostAlloc -> h_out");

	cudaHostGetDevicePointer((void**)&d_in, h_in, 0);
	cudaHostGetDevicePointer((void**)&d_out, h_out, 0);


	char* column_name = (char*) args->args[0];
	char* table_name = (char*) args->args[1];
	char* schema_name = (char*) args->args[2];

	DBUG_PRINT("info", ("column_name [%s], table_name [%s], schema_name [%s]", column_name, table_name, schema_name));
	fprintf(stderr, "column_name [%s], table_name [%s], schema_name [%s]\n", column_name, table_name, schema_name);
	fflush(stderr);

	THD *thd = current_thd;

	TABLE_LIST* table_list = new TABLE_LIST;	
	memset((char*) table_list, 0, sizeof(TABLE_LIST));

	DBUG_PRINT("info", ("table_list->init_one_table"));
	table_list->init_one_table(schema_name, strlen(schema_name), table_name, strlen(table_name), table_name, TL_READ);
	DBUG_PRINT("info", ("open_and_lock_tables"));
	open_and_lock_tables(thd, table_list, FALSE, MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT);

	TABLE* table = table_list->table;

	clock_t cpu_clock;
	cpu_clock = clock();
	table->file->ha_rnd_init(true);

	while (table->file->ha_rnd_next(table->record[0]) == 0){
		h_in[index++] = table->field[1]->val_real();
	}
	table->file->ha_rnd_end();
	cpu_clock = clock() - cpu_clock;
	fprintf(stderr, "gsum -> index [%d]\n", index);
	fprintf(stderr, "gsum -> fill cache within [%f seconds]\n", ((float)cpu_clock)/CLOCKS_PER_SEC);
	fflush(stderr);
	

	cudaEvent_t start, stop;
	float elapsedTime;

	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	cudaEventRecord(start, 0);
	ReductionTask reduction_task(MAXIMUM_ELEMENTS_IN_CACHE, sizeof(double), CUDA_BLOCK_SIZE, CUDA_THREAD_PER_BLOCK_SIZE, R_SUM, R_DOUBLE);
	reductionWorkerUsingMappedMemory<double>(d_in, d_out, &reduction_task);
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	cudaEventElapsedTime(&elapsedTime, start, stop);

	double gpu_sum = 0;
	for (unsigned int i = 0; i < CUDA_BLOCK_SIZE; i++)
	{
		gpu_sum += ((double*)h_out)[i];
	}

	float bandwidthInMBs = (1e3f * MAXIMUM_ELEMENTS_IN_CACHE*sizeof(double)) / (elapsedTime * (float)(1 << 20));
	fprintf(stderr, "gpu result [%f], gpu time [%f seconds] bandwidth (mb) [%f]\n", gpu_sum, elapsedTime/1000.0, bandwidthInMBs);
	fflush(stderr);

	cudaFreeHost(h_in);
	CUDA_CHECK_ERRORS("cudaFreeHost -> h_in");
	cudaFreeHost(h_out);
	CUDA_CHECK_ERRORS("cudaFreeHost -> h_out");

	thd->cleanup_after_query();
	DBUG_PRINT("info", ("about to delete table_list"));
	delete table_list;

	DBUG_RETURN(gpu_sum);
}