|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/src/uds/cacheCounters.c#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "cacheCounters.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "atomicDefs.h"
|
|
Packit Service |
310c69 |
#include "compiler.h"
|
|
Packit Service |
310c69 |
#include "errors.h"
|
|
Packit Service |
310c69 |
#include "permassert.h"
|
|
Packit Service |
310c69 |
#include "stringUtils.h"
|
|
Packit Service |
310c69 |
#include "uds.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
void incrementCacheCounter(CacheCounters *counters,
|
|
Packit Service |
310c69 |
int probeType,
|
|
Packit Service |
310c69 |
CacheResultKind kind)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
CacheProbeType basicProbeType = probeType & ~CACHE_PROBE_IGNORE_FAILURE;
|
|
Packit Service |
310c69 |
int result = ASSERT(basicProbeType <= CACHE_PROBE_RECORD_RETRY,
|
|
Packit Service |
310c69 |
"invalid cache probe type %#x", probeType);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = ASSERT(kind <= CACHE_RESULT_QUEUED,
|
|
Packit Service |
310c69 |
"invalid cache probe result type %#x", kind);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
if (((probeType & CACHE_PROBE_IGNORE_FAILURE) != 0)
|
|
Packit Service |
310c69 |
&& (kind != CACHE_RESULT_HIT)) {
|
|
Packit Service |
310c69 |
return;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
CacheCountsByKind *kindCounts;
|
|
Packit Service |
310c69 |
switch (basicProbeType) {
|
|
Packit Service |
310c69 |
case CACHE_PROBE_INDEX_FIRST:
|
|
Packit Service |
310c69 |
kindCounts = &counters->firstTime.indexPage;
|
|
Packit Service |
310c69 |
break;
|
|
Packit Service |
310c69 |
case CACHE_PROBE_RECORD_FIRST:
|
|
Packit Service |
310c69 |
kindCounts = &counters->firstTime.recordPage;
|
|
Packit Service |
310c69 |
break;
|
|
Packit Service |
310c69 |
case CACHE_PROBE_INDEX_RETRY:
|
|
Packit Service |
310c69 |
kindCounts = &counters->retried.indexPage;
|
|
Packit Service |
310c69 |
break;
|
|
Packit Service |
310c69 |
case CACHE_PROBE_RECORD_RETRY:
|
|
Packit Service |
310c69 |
kindCounts = &counters->retried.recordPage;
|
|
Packit Service |
310c69 |
break;
|
|
Packit Service |
310c69 |
default:
|
|
Packit Service |
310c69 |
// Never used but the compiler hasn't figured that out.
|
|
Packit Service |
310c69 |
return;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
uint64_t *myCounter;
|
|
Packit Service |
310c69 |
switch (kind) {
|
|
Packit Service |
310c69 |
case CACHE_RESULT_MISS:
|
|
Packit Service |
310c69 |
myCounter = &kindCounts->misses;
|
|
Packit Service |
310c69 |
break;
|
|
Packit Service |
310c69 |
case CACHE_RESULT_QUEUED:
|
|
Packit Service |
310c69 |
myCounter = &kindCounts->queued;
|
|
Packit Service |
310c69 |
break;
|
|
Packit Service |
310c69 |
case CACHE_RESULT_HIT:
|
|
Packit Service |
310c69 |
myCounter = &kindCounts->hits;
|
|
Packit Service |
310c69 |
break;
|
|
Packit Service |
310c69 |
default:
|
|
Packit Service |
310c69 |
// Never used but the compiler hasn't figured that out.
|
|
Packit Service |
310c69 |
return;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
// XXX Vile case makes many assumptions. Counters should be declared atomic.
|
|
Packit Service |
310c69 |
atomic64_inc((atomic64_t *) myCounter);
|
|
Packit Service |
310c69 |
}
|