Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8c0bd9

Browse files
committed
Remove now-unnecessary thread pointer arguments in pgbench.
Not required after nuking the zipfian thread-local cache.Also add a comment about hazardous pointer punning in threadRun(),and avoid using "thread" to refer to the threads array as a whole.Fabien Coelho and Tom Lane, per suggestion from Alvaro HerreraDiscussion:https://postgr.es/m/alpine.DEB.2.21.1904032126060.7997@lancre
1 parentc50b315 commitd8c0bd9

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,9 @@ static void setNullValue(PgBenchValue *pv);
575575
staticvoidsetBoolValue(PgBenchValue*pv,boolbval);
576576
staticvoidsetIntValue(PgBenchValue*pv,int64ival);
577577
staticvoidsetDoubleValue(PgBenchValue*pv,doubledval);
578-
staticboolevaluateExpr(TState*thread,CState*st,PgBenchExpr*expr,
578+
staticboolevaluateExpr(CState*st,PgBenchExpr*expr,
579579
PgBenchValue*retval);
580-
staticConnectionStateEnumexecuteMetaCommand(TState*thread,CState*st,
581-
instr_time*now);
580+
staticConnectionStateEnumexecuteMetaCommand(CState*st,instr_time*now);
582581
staticvoiddoLog(TState*thread,CState*st,
583582
StatsData*agg,boolskipped,doublelatency,doublelag);
584583
staticvoidprocessXactStats(TState*thread,CState*st,instr_time*now,
@@ -1744,7 +1743,7 @@ isLazyFunc(PgBenchFunction func)
17441743

17451744
/* lazy evaluation of some functions */
17461745
staticbool
1747-
evalLazyFunc(TState*thread,CState*st,
1746+
evalLazyFunc(CState*st,
17481747
PgBenchFunctionfunc,PgBenchExprLink*args,PgBenchValue*retval)
17491748
{
17501749
PgBenchValuea1,
@@ -1755,7 +1754,7 @@ evalLazyFunc(TState *thread, CState *st,
17551754
Assert(isLazyFunc(func)&&args!=NULL&&args->next!=NULL);
17561755

17571756
/* args points to first condition */
1758-
if (!evaluateExpr(thread,st,args->expr,&a1))
1757+
if (!evaluateExpr(st,args->expr,&a1))
17591758
return false;
17601759

17611760
/* second condition for AND/OR and corresponding branch for CASE */
@@ -1779,7 +1778,7 @@ evalLazyFunc(TState *thread, CState *st,
17791778
return true;
17801779
}
17811780

1782-
if (!evaluateExpr(thread,st,args->expr,&a2))
1781+
if (!evaluateExpr(st,args->expr,&a2))
17831782
return false;
17841783

17851784
if (a2.type==PGBT_NULL)
@@ -1814,7 +1813,7 @@ evalLazyFunc(TState *thread, CState *st,
18141813
return true;
18151814
}
18161815

1817-
if (!evaluateExpr(thread,st,args->expr,&a2))
1816+
if (!evaluateExpr(st,args->expr,&a2))
18181817
return false;
18191818

18201819
if (a2.type==PGBT_NULL)
@@ -1833,17 +1832,17 @@ evalLazyFunc(TState *thread, CState *st,
18331832
casePGBENCH_CASE:
18341833
/* when true, execute branch */
18351834
if (valueTruth(&a1))
1836-
returnevaluateExpr(thread,st,args->expr,retval);
1835+
returnevaluateExpr(st,args->expr,retval);
18371836

18381837
/* now args contains next condition or final else expression */
18391838
args=args->next;
18401839

18411840
/* final else case? */
18421841
if (args->next==NULL)
1843-
returnevaluateExpr(thread,st,args->expr,retval);
1842+
returnevaluateExpr(st,args->expr,retval);
18441843

18451844
/* no, another when, proceed */
1846-
returnevalLazyFunc(thread,st,PGBENCH_CASE,args,retval);
1845+
returnevalLazyFunc(st,PGBENCH_CASE,args,retval);
18471846

18481847
default:
18491848
/* internal error, cannot get here */
@@ -1861,7 +1860,7 @@ evalLazyFunc(TState *thread, CState *st,
18611860
* which do not require lazy evaluation.
18621861
*/
18631862
staticbool
1864-
evalStandardFunc(TState*thread,CState*st,
1863+
evalStandardFunc(CState*st,
18651864
PgBenchFunctionfunc,PgBenchExprLink*args,
18661865
PgBenchValue*retval)
18671866
{
@@ -1873,7 +1872,7 @@ evalStandardFunc(TState *thread, CState *st,
18731872

18741873
for (nargs=0;nargs<MAX_FARGS&&l!=NULL;nargs++,l=l->next)
18751874
{
1876-
if (!evaluateExpr(thread,st,l->expr,&vargs[nargs]))
1875+
if (!evaluateExpr(st,l->expr,&vargs[nargs]))
18771876
return false;
18781877
has_null |=vargs[nargs].type==PGBT_NULL;
18791878
}
@@ -2408,13 +2407,13 @@ evalStandardFunc(TState *thread, CState *st,
24082407

24092408
/* evaluate some function */
24102409
staticbool
2411-
evalFunc(TState*thread,CState*st,
2410+
evalFunc(CState*st,
24122411
PgBenchFunctionfunc,PgBenchExprLink*args,PgBenchValue*retval)
24132412
{
24142413
if (isLazyFunc(func))
2415-
returnevalLazyFunc(thread,st,func,args,retval);
2414+
returnevalLazyFunc(st,func,args,retval);
24162415
else
2417-
returnevalStandardFunc(thread,st,func,args,retval);
2416+
returnevalStandardFunc(st,func,args,retval);
24182417
}
24192418

24202419
/*
@@ -2424,7 +2423,7 @@ evalFunc(TState *thread, CState *st,
24242423
* the value itself is returned through the retval pointer.
24252424
*/
24262425
staticbool
2427-
evaluateExpr(TState*thread,CState*st,PgBenchExpr*expr,PgBenchValue*retval)
2426+
evaluateExpr(CState*st,PgBenchExpr*expr,PgBenchValue*retval)
24282427
{
24292428
switch (expr->etype)
24302429
{
@@ -2453,7 +2452,7 @@ evaluateExpr(TState *thread, CState *st, PgBenchExpr *expr, PgBenchValue *retval
24532452
}
24542453

24552454
caseENODE_FUNCTION:
2456-
returnevalFunc(thread,st,
2455+
returnevalFunc(st,
24572456
expr->u.function.function,
24582457
expr->u.function.args,
24592458
retval);
@@ -3072,7 +3071,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
30723071
* - on sleep CSTATE_SLEEP
30733072
* - else CSTATE_END_COMMAND
30743073
*/
3075-
st->state=executeMetaCommand(thread,st,&now);
3074+
st->state=executeMetaCommand(st,&now);
30763075
}
30773076

30783077
/*
@@ -3304,7 +3303,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
33043303
* take no time to execute.
33053304
*/
33063305
staticConnectionStateEnum
3307-
executeMetaCommand(TState*thread,CState*st,instr_time*now)
3306+
executeMetaCommand(CState*st,instr_time*now)
33083307
{
33093308
Command*command=sql_script[st->use_file].commands[st->command];
33103309
intargc;
@@ -3348,7 +3347,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now)
33483347
PgBenchExpr*expr=command->expr;
33493348
PgBenchValueresult;
33503349

3351-
if (!evaluateExpr(thread,st,expr,&result))
3350+
if (!evaluateExpr(st,expr,&result))
33523351
{
33533352
commandFailed(st,argv[0],"evaluation of meta-command failed");
33543353
returnCSTATE_ABORTED;
@@ -3367,7 +3366,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now)
33673366
PgBenchValueresult;
33683367
boolcond;
33693368

3370-
if (!evaluateExpr(thread,st,expr,&result))
3369+
if (!evaluateExpr(st,expr,&result))
33713370
{
33723371
commandFailed(st,argv[0],"evaluation of meta-command failed");
33733372
returnCSTATE_ABORTED;
@@ -3390,7 +3389,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now)
33903389
returnCSTATE_END_COMMAND;
33913390
}
33923391

3393-
if (!evaluateExpr(thread,st,expr,&result))
3392+
if (!evaluateExpr(st,expr,&result))
33943393
{
33953394
commandFailed(st,argv[0],"evaluation of meta-command failed");
33963395
returnCSTATE_ABORTED;
@@ -4773,7 +4772,7 @@ addScript(ParsedScript script)
47734772
* progress report. On exit, they are updated with the new stats.
47744773
*/
47754774
staticvoid
4776-
printProgressReport(TState*thread,int64test_start,int64now,
4775+
printProgressReport(TState*threads,int64test_start,int64now,
47774776
StatsData*last,int64*last_report)
47784777
{
47794778
/* generate and show report */
@@ -4801,10 +4800,10 @@ printProgressReport(TState *thread, int64 test_start, int64 now,
48014800
initStats(&cur,0);
48024801
for (inti=0;i<nthreads;i++)
48034802
{
4804-
mergeSimpleStats(&cur.latency,&thread[i].stats.latency);
4805-
mergeSimpleStats(&cur.lag,&thread[i].stats.lag);
4806-
cur.cnt+=thread[i].stats.cnt;
4807-
cur.skipped+=thread[i].stats.skipped;
4803+
mergeSimpleStats(&cur.latency,&threads[i].stats.latency);
4804+
mergeSimpleStats(&cur.lag,&threads[i].stats.lag);
4805+
cur.cnt+=threads[i].stats.cnt;
4806+
cur.skipped+=threads[i].stats.skipped;
48084807
}
48094808

48104809
/* we count only actually executed transactions */
@@ -4874,7 +4873,7 @@ printSimpleStats(const char *prefix, SimpleStats *ss)
48744873

48754874
/* print out results */
48764875
staticvoid
4877-
printResults(TState*threads,StatsData*total,instr_timetotal_time,
4876+
printResults(StatsData*total,instr_timetotal_time,
48784877
instr_timeconn_total_time,int64latency_late)
48794878
{
48804879
doubletime_include,
@@ -5887,7 +5886,7 @@ main(int argc, char **argv)
58875886
*/
58885887
INSTR_TIME_SET_CURRENT(total_time);
58895888
INSTR_TIME_SUBTRACT(total_time,start_time);
5890-
printResults(threads,&stats,total_time,conn_total_time,latency_late);
5889+
printResults(&stats,total_time,conn_total_time,latency_late);
58915890

58925891
if (exit_code!=0)
58935892
fprintf(stderr,"Run was aborted; the above results are incomplete.\n");
@@ -6146,7 +6145,14 @@ threadRun(void *arg)
61466145
now=INSTR_TIME_GET_MICROSEC(now_time);
61476146
if (now >=next_report)
61486147
{
6149-
printProgressReport(thread,thread_start,now,&last,&last_report);
6148+
/*
6149+
* Horrible hack: this relies on the thread pointer we are
6150+
* passed to be equivalent to threads[0], that is the first
6151+
* entry of the threads array. That is why this MUST be done
6152+
* by thread 0 and not any other.
6153+
*/
6154+
printProgressReport(thread,thread_start,now,
6155+
&last,&last_report);
61506156

61516157
/*
61526158
* Ensure that the next report is in the future, in case

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp