Skip to content

Commit fb5bcfc

Browse files
committed
implement simulate latency use RDTSC instruction
1 parent 877c7d5 commit fb5bcfc

File tree

8 files changed

+116
-3
lines changed

8 files changed

+116
-3
lines changed

build_mysql.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ MYSQL_HOME=/home/vldb/mysql-plnvm
55
IS_DEBUG=0
66
#IS_DEBUG=1
77

8+
#Next paper configs PL-NVM ##############################
89
#BUILD_NAME="-DUNIV_TRACE_RECOVERY_TIME"
910
#BUILD_NAME="-DUNIV_TRACE_FLUSH_TIME -DUNIV_SKIPLOG"
1011
#BUILD_NAME="-DUNIV_PMEMOBJ_WAL -DUNIV_TRACE_FLUSH_TIME"
1112
#BUILD_NAME="-DUNIV_PMEMOBJ_WAL -DUNIV_PMEMOBJ_WAL_ELR -DUNIV_TRACE_FLUSH_TIME"
1213
#BUILD_NAME="-DUNIV_NVM_LOG -DUNIV_PMEMOBJ_WAL -DUNIV_TRACE_FLUSH_TIME"
13-
BUILD_NAME="-DUNIV_PMEMOBJ_PPL_STAT -DUNIV_PMEMOBJ_PAGE_LOG -DUNIV_PMEMOBJ_PART_PL -DUNIV_PMEMOBJ_PL -DUNIV_TRACE_RECOVERY_TIME"
14+
#BUILD_NAME="-DUNIV_PMEMOBJ_PPL_STAT -DUNIV_PMEMOBJ_PAGE_LOG -DUNIV_PMEMOBJ_PART_PL -DUNIV_PMEMOBJ_PL -DUNIV_TRACE_RECOVERY_TIME"
1415
#BUILD_NAME="-DUNIV_PMEMOBJ_PPL_STAT -DUNIV_PMEMOBJ_PAGE_LOG -DUNIV_PMEMOBJ_PART_PL -DUNIV_PMEMOBJ_PART_PL_DEBUG -DUNIV_PMEMOBJ_PL -DUNIV_TRACE_FLUSH_TIME"
16+
#######################################
17+
18+
##### Simulate latency
19+
BUILD_NAME="-DUNIV_SIM_LATENCY -DUNIV_OPENMP -DUNIV_PMEMOBJ_BLOOM -DUNIV_PMEMOBJ_BUF -DUNIV_PMEMOBJ_BUF_PARTITION -DUNIV_PMEMOBJ_BUF_FLUSHER -DUNIV_PMEMOBJ_BUF_RECOVERY -DUNIV_TRACE_FLUSH_TIME"
1520

1621
####debug with valid mtr
1722
#BUILD_NAME="-DUNIV_PMEMOBJ_VALID_MTR -DUNIV_PMEMOBJ_PPL_STAT -DUNIV_PMEMOBJ_PAGE_LOG -DUNIV_PMEMOBJ_PART_PL -DUNIV_PMEMOBJ_PL -DUNIV_TRACE_RECOVERY_TIME"

storage/innobase/handler/ha_innodb.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,6 +3769,11 @@ innobase_init(
37693769
srv_ppl_log_files_per_bucket = 1;
37703770
}
37713771
#endif
3772+
#if defined (UNIV_PMEM_SIM_LATENCY)
3773+
if (!srv_pmem_sim_latency) {
3774+
srv_pmem_sim_latency = 1000 ; //1000 ns
3775+
}
3776+
#endif
37723777

37733778
#if defined(UNIV_PMEMOBJ_BUF)
37743779
if (!srv_pmem_buf_bucket_size) {
@@ -19623,6 +19628,13 @@ static MYSQL_SYSVAR_DOUBLE(pmem_bloom_fpr, srv_pmem_bloom_fpr,
1962319628
NULL, NULL, 0.001, 0, 1,0);
1962419629
#endif
1962519630

19631+
#if defined (UNIV_PMEM_SIM_LATENCY)
19632+
static MYSQL_SYSVAR_ULONG(pmem_sim_latency, srv_pmem_sim_latency,
19633+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
19634+
"Additional latency , from 1 ns to 10000000, default 1000.",
19635+
NULL, NULL, 1000, 1, 10000000,0);
19636+
#endif
19637+
1962619638
#if defined (UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL) || defined (UNIV_PMEMOBJ_PART_PL)
1962719639
static MYSQL_SYSVAR_STR(pmem_home_dir, srv_pmem_home_dir,
1962819640
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
@@ -20536,6 +20548,9 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
2053620548
MYSQL_SYSVAR(pmem_n_flush_threads),
2053720549
MYSQL_SYSVAR(pmem_flush_threshold),
2053820550
#endif
20551+
#if defined (UNIV_PMEM_SIM_LATENCY)
20552+
MYSQL_SYSVAR(pmem_sim_latency),
20553+
#endif
2053920554
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
2054020555
MYSQL_SYSVAR(pmem_n_space_bits),
2054120556
MYSQL_SYSVAR(pmem_page_per_bucket_bits),

storage/innobase/include/my_pmemobj.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ struct __pmem_wrapper {
312312

313313
#if defined (UNIV_PMEMOBJ_LSB)
314314
PMEM_LSB* plsb;
315+
#endif
316+
#if defined (UNIV_PMEM_SIM_LATENCY)
317+
uint64_t PMEM_SIM_CPU_CYCLES; //used in simulate latency
315318
#endif
316319
bool is_new;
317320
};
@@ -332,7 +335,15 @@ pm_wrapper_free(PMEM_WRAPPER* pmw);
332335
PMEMoid pm_pop_alloc_bytes(PMEMobjpool* pop, size_t size);
333336
void pm_pop_free(PMEMobjpool* pop);
334337

335-
338+
#if defined (UNIV_PMEM_SIM_LATENCY)
339+
#define PMEM_DELAY(start, end, t) do {\
340+
start = my_timer_cycles();\
341+
end = start;\
342+
while( (end - start) < t){\
343+
end = my_timer_cycles();\
344+
}\
345+
} while(0)
346+
#endif
336347
//////////////////// PARTITIONED-LOG 2018.11.2/////////////
337348

338349
#if defined (UNIV_PMEMOBJ_PL)

storage/innobase/include/srv0srv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ extern ulong srv_pmem_page_per_bucket_bits;
286286
extern ulong srv_pmem_bloom_n_elements;
287287
extern double srv_pmem_bloom_fpr;
288288
#endif
289+
290+
#if defined (UNIV_PMEM_SIM_LATENCY)
291+
extern ulong srv_pmem_sim_latency;
292+
#endif
293+
289294
#if defined(UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG) || defined(UNIV_PMEMOBJ_WAL) || defined (UNIV_PMEMOBJ_PART_PL)
290295
extern char* srv_pmem_home_dir;
291296
extern ulong srv_pmem_pool_size;

storage/innobase/pmem/pmem0buf.cc

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#include "buf0dblwr.h"
2424

2525

26+
#if defined (UNIV_PMEM_SIM_LATENCY)
27+
static uint64_t PMEM_SIM_LATENCY = 1000;
28+
static float PMEM_CPU_FREQ = 2.2;
29+
static uint64_t PMEM_SIM_CPU_CYCLES = PMEM_SIM_LATENCY * PMEM_CPU_FREQ;
30+
#endif //UNIV_PMEM_SIM_LATENCY
31+
2632
#if defined (UNIV_PMEMOBJ_BUF)
2733
/*
2834
There are two types of structure need to be allocated: structures in NVM that non-volatile after shutdown server or power-off and D-RAM structures that only need when the server is running.
@@ -733,6 +739,11 @@ TX_BEGIN(pop) {
733739
//pspec_block->file_handle = node->handle;
734740
strcpy(pspec_block->file_name, node->name);
735741

742+
#if defined (UNIV_PMEM_SIM_LATENCY)
743+
/*5 times write to NVM*/
744+
PMEM_DELAY(start_cycle, end_cycle, 5 * pmw->PMEM_SIM_CPU_CYCLES);
745+
#endif
746+
736747
#if defined (UNIV_PMEMOBJ_NO_PERSIST)
737748
pmemobj_memcpy_persist(pop, pdata + pspec_block->pmemaddr, src_data, page_size);
738749
//memcpy(pdata + pspec_block->pmemaddr, src_data, page_size);
@@ -830,6 +841,10 @@ TX_BEGIN(pop) {
830841
}
831842
}
832843
pfree_block->sync = sync;
844+
#if defined (UNIV_PMEM_SIM_LATENCY)
845+
/*3 times write to NVM*/
846+
PMEM_DELAY(start_cycle, end_cycle, 3 * pmw->PMEM_SIM_CPU_CYCLES);
847+
#endif
833848
#if defined (UNIV_PMEMOBJ_NO_PERSIST)
834849
pmemobj_memcpy_persist(pop, pdata + pfree_block->pmemaddr, src_data, page_size);
835850
//memcpy(pdata + pfree_block->pmemaddr, src_data, page_size);
@@ -923,6 +938,10 @@ TX_BEGIN(pop) {
923938
else
924939
++(phashlist->n_sio_pending);
925940

941+
#if defined (UNIV_PMEM_SIM_LATENCY)
942+
/*7 times write to NVM*/
943+
PMEM_DELAY(start_cycle, end_cycle, 7 * pmw->PMEM_SIM_CPU_CYCLES);
944+
#endif
926945
// HANDLE FULL LIST ////////////////////////////////////////////////////////////
927946
if (phashlist->cur_pages >= phashlist->max_pages * PMEM_BUF_FLUSH_PCT) {
928947
//(3) The hashlist is (nearly) full, flush it and assign a free list
@@ -1303,6 +1322,10 @@ pm_handle_finished_block(
13031322
for (i = 0; i < pflush_list->max_pages; i++) {
13041323
D_RW(D_RW(pflush_list->arr)[i])->state = PMEM_FREE_BLOCK;
13051324
D_RW(D_RW(pflush_list->arr)[i])->sync = false;
1325+
#if defined (UNIV_PMEM_SIM_LATENCY)
1326+
/*2 times write to NVM*/
1327+
PMEM_DELAY(start_cycle, end_cycle, 2 * pmw->PMEM_SIM_CPU_CYCLES);
1328+
#endif
13061329
}
13071330

13081331
pflush_list->cur_pages = 0;
@@ -1336,11 +1359,20 @@ pm_handle_finished_block(
13361359
PMEM_BUF_FREE_POOL* pfree_pool;
13371360
pfree_pool = D_RW(buf->free_pool);
13381361

1362+
#if defined (UNIV_PMEM_SIM_LATENCY)
1363+
/*7 times write to NVM*/
1364+
PMEM_DELAY(start_cycle, end_cycle, 7 * pmw->PMEM_SIM_CPU_CYCLES);
1365+
#endif
1366+
13391367
//printf("PMEM_DEBUG: in fil_aio_wait(), try to lock free_pool list id: %zd, cur_lists in free_pool= %zd \n", pflush_list->list_id, pfree_pool->cur_lists);
13401368
pmemobj_rwlock_wrlock(pop, &pfree_pool->lock);
13411369

13421370
POBJ_LIST_INSERT_TAIL(pop, &pfree_pool->head, flush_list, list_entries);
13431371
pfree_pool->cur_lists++;
1372+
#if defined (UNIV_PMEM_SIM_LATENCY)
1373+
/*2 times write to NVM*/
1374+
PMEM_DELAY(start_cycle, end_cycle, 2 * pmw->PMEM_SIM_CPU_CYCLES);
1375+
#endif
13441376
//wakeup who is waitting for free_pool available
13451377
os_event_set(buf->free_pool_event);
13461378

@@ -1583,7 +1615,7 @@ pm_buf_read(
15831615

15841616
#if defined (UNIV_PMEMOBJ_BLOOM)
15851617
if (bloom_ret == BLOOM_MAY_EXIST){
1586-
printf("++++> BLOOM false positive fold %zu \n", page_id.fold());
1618+
//printf("++++> BLOOM false positive fold %zu \n", page_id.fold());
15871619
buf->cbf->n_false_pos_reads++;
15881620
}
15891621
#endif

storage/innobase/pmem/pmem0log.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ static bool USE_BIT_ARRAY = true;
7171
//static bool USE_BIT_ARRAY = false;
7272
static uint64_t BIT_BLOCK_SIZE = sizeof(long long);
7373

74+
/*call pmemobj_persist() at every log record write*/
75+
static bool PERSIST_AT_WRITE = true;
76+
7477
#endif //UNIV_PMEMOBJ_PL
7578
//////////////// NEW PMEM PARTITION LOG /////////////
7679

@@ -1710,6 +1713,9 @@ pm_ppl_write_rec(
17101713
#endif
17111714
//move the diskaddr on the line ahead, the written size should be aligned with 512B for DIRECT_IO works
17121715
pline->diskaddr += plogbuf->size;
1716+
if (PERSIST_AT_WRITE){
1717+
pmemobj_persist(pop, &pline->diskaddr, sizeof(pline->diskaddr));
1718+
}
17131719

17141720
// (1.4) write log rec on new buf
17151721
D_RW(free_buf)->hashed_id = pline->hashed_id;
@@ -1778,15 +1784,28 @@ pm_ppl_write_rec(
17781784
//update the oldest
17791785
if (pline->oldest_block_off == UINT32_MAX) {
17801786
pline->oldest_block_off = item->block_off;
1787+
if (PERSIST_AT_WRITE){
1788+
pmemobj_persist(pop, &pline->oldest_block_off, sizeof(pline->oldest_block_off));
1789+
}
17811790
}
17821791
//test
17831792
/*insert the pair (offset, bid) into the set*/
17841793
write_off = plog_block->start_diskaddr + plog_block->start_off;
17851794
pline->offset_map->insert( std::make_pair(write_off, item->block_off));
17861795

1796+
if (PERSIST_AT_WRITE){
1797+
pmemobj_persist(pop, plog_block, sizeof(PMEM_PAGE_LOG_BLOCK));
1798+
}
1799+
17871800
}
17881801
plog_block->lastLSN = rec_lsn;
17891802

1803+
/*persist the plogblock*/
1804+
if (PERSIST_AT_WRITE){
1805+
pmemobj_persist(pop, D_RW(free_buf), sizeof(PMEM_PAGE_LOG_BUF));
1806+
pmemobj_persist(pop, plogbuf, sizeof(PMEM_PAGE_LOG_BUF));
1807+
}
1808+
17901809

17911810
// (1.6) assign a pointer in the flusher to the full log buf, this function return immediately
17921811
pm_log_buf_assign_flusher(ppl, plogbuf);
@@ -1814,6 +1833,9 @@ pm_ppl_write_rec(
18141833

18151834
old_off = plogbuf->cur_off;
18161835
plogbuf->cur_off += rec_size;
1836+
if (PERSIST_AT_WRITE){
1837+
pmemobj_persist(pop, &plogbuf->cur_off, sizeof(plogbuf->cur_off));
1838+
}
18171839

18181840
if (!pline->is_req_checkpoint){
18191841
/*comment this line to disable checkpoint (for debugging)*/
@@ -1850,13 +1872,21 @@ pm_ppl_write_rec(
18501872
//update the oldest
18511873
if (pline->oldest_block_off == UINT32_MAX) {
18521874
pline->oldest_block_off = item->block_off;
1875+
if (PERSIST_AT_WRITE){
1876+
pmemobj_persist(pop, &pline->oldest_block_off, sizeof(pline->oldest_block_off));
1877+
}
18531878
}
18541879
//test
18551880
/*insert the pair (offset, bid) into the set*/
18561881
write_off = plog_block->start_diskaddr + plog_block->start_off;
1882+
18571883
pmemobj_rwlock_wrlock(pop, &pline->meta_lock);
18581884
pline->offset_map->insert( std::make_pair(write_off, item->block_off));
18591885
pmemobj_rwlock_unlock(pop, &pline->meta_lock);
1886+
1887+
if (PERSIST_AT_WRITE){
1888+
pmemobj_persist(pop, plog_block, sizeof(PMEM_PAGE_LOG_BLOCK));
1889+
}
18601890
}
18611891

18621892
plog_block->lastLSN = rec_lsn;
@@ -2397,6 +2427,7 @@ pm_ppl_check_for_ckpt(
23972427

23982428
//Method 1
23992429
pline->ckpt_lsn = oldest_lsn + delta;
2430+
//pmemobj_persist(pop, &pline->ckpt_lsn, sizeof(pline->ckpt_lsn));
24002431

24012432
//Method 2 => no ckpt call
24022433
//pline->ckpt_lsn = oldest_lsn + 1000000 ;
@@ -2408,6 +2439,7 @@ pm_ppl_check_for_ckpt(
24082439
pmemobj_rwlock_wrlock(pop, &ppl->ckpt_lock);
24092440
if (ppl->max_oldest_lsn < pline->ckpt_lsn){
24102441
ppl->max_oldest_lsn = pline->ckpt_lsn;
2442+
//pmemobj_persist(pop, &ppl->max_oldest_lsn, sizeof(ppl->max_oldest_lsn));
24112443
}
24122444

24132445
//printf("SET is_req_checkpoint to true pline %zu \n", pline->hashed_id);

storage/innobase/srv/srv0srv.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ ulong srv_pmem_bloom_n_elements = 10000000;
229229
double srv_pmem_bloom_fpr = 0.01;
230230
#endif
231231

232+
#if defined (UNIV_PMEM_SIM_LATENCY)
233+
ulong srv_pmem_sim_latency = 1000;
234+
#endif
235+
232236
#if defined(UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL) || defined (UNIV_PMEMOBJ_PART_PL)
233237
char* srv_pmem_home_dir = NULL;
234238
ulong srv_pmem_pool_size = 8 * 1024;

storage/innobase/srv/srv0start.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,9 @@ innobase_start_or_create_for_mysql(void)
18091809
#ifdef UNIV_PMEMOBJ_WAL
18101810
ib::info() << "======= Hello PMEMOBJ WAL from VLDB lab ========\n";
18111811
#endif
1812+
#if defined (UNIV_PMEM_SIM_LATENCY)
1813+
ib::info() << "======= Simulate addtional latency %zu ns ========\n", srv_pmem_sim_latency;
1814+
#endif
18121815
#ifdef UNIV_PMEOBJ_BUF
18131816
ib::info() << "======== pool_size =" << srv_pmem_pool_size <<
18141817
"MB; srv_pmem_buf_size= " << srv_pmem_buf_size << "MB; " <<
@@ -1973,6 +1976,12 @@ innobase_start_or_create_for_mysql(void)
19731976
fsp_init();
19741977
log_init();
19751978

1979+
#if defined (UNIV_PMEM_SIM_LATENCY)
1980+
PMEM_SIM_LATENCY = srv_pmem_sim_latency;
1981+
PMEM_SIM_CPU_CYCLES = PMEM_SIM_LATENCY * 1.0 * PMEM_CPU_FREQ;
1982+
pmw->PMEM_SIM_CPU_CYCLES = PMEM_SIM_CPU_CYCLES;
1983+
#endif
1984+
19761985
#if defined (UNIV_PMEMOBJ_BUF)
19771986
size_t buf_size = srv_pmem_buf_size * 1024 * 1024;
19781987
#if defined (UNIV_PMEMOBJ_LSB)

0 commit comments

Comments
 (0)