Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes 20250103 #12335

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/flow-worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ static TmEcode FlowWorker(ThreadVars *tv, Packet *p, void *data)

/* update time */
if (!(PKT_IS_PSEUDOPKT(p))) {
TimeSetByThread(tv->id, p->ts);
TimeSetByThread(tv, p->ts);
}

/* handle Flow */
Expand Down
7 changes: 7 additions & 0 deletions src/threadvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ typedef struct ThreadVars_ {
* void pointers in and out. */
void *(*tm_func)(void *);

SCTime_t pktts; /**< current packet time of this thread
* (offline mode) */
SCTime_t sys_sec_stamp; /**< timestamp in real system
* time when the pktts was last updated. */

char name[16];
char *printable_name;
char *thread_group_name;
Expand Down Expand Up @@ -139,6 +144,8 @@ typedef struct ThreadVars_ {
Storage storage[];
} ThreadVars;

void TimeSetByThread(ThreadVars *thread_v, SCTime_t tv);

/** Thread setup flags: */
#define THREAD_SET_AFFINITY 0x01 /** CPU/Core affinity */
#define THREAD_SET_PRIORITY 0x02 /** Real time priority */
Expand Down
47 changes: 21 additions & 26 deletions src/tm-threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -2070,10 +2070,6 @@ typedef struct Thread_ {
int type;
int in_use; /**< bool to indicate this is in use */

SCTime_t pktts; /**< current packet time of this thread
* (offline mode) */
SCTime_t sys_sec_stamp; /**< timestamp in real system
* time when the pktts was last updated. */
} Thread;

typedef struct Threads_ {
Expand Down Expand Up @@ -2185,30 +2181,21 @@ void TmThreadsUnregisterThread(const int id)
SCMutexUnlock(&thread_store_lock);
}

void TmThreadsSetThreadTimestamp(const int id, const SCTime_t ts)
void TmThreadsSetThreadTimestamp(ThreadVars *thread_v, const SCTime_t ts)
{
SCMutexLock(&thread_store_lock);
if (unlikely(id <= 0 || id > (int)thread_store.threads_size)) {
SCMutexUnlock(&thread_store_lock);
return;
}

int idx = id - 1;
Thread *t = &thread_store.threads[idx];
t->pktts = ts;
thread_v->pktts = ts;
SCTime_t now = SCTimeGetTime();

#ifdef DEBUG
if (t->sys_sec_stamp.secs != 0) {
SCTime_t tmpts = SCTIME_ADD_SECS(t->sys_sec_stamp, 3);
if (thread_v->sys_sec_stamp.secs != 0) {
SCTime_t tmpts = SCTIME_ADD_SECS(thread_v->sys_sec_stamp, 3);
if (SCTIME_CMP_LT(tmpts, now)) {
SCLogDebug("%s: thread slept for %u secs", t->name, (uint32_t)(now.secs - tmpts.secs));
}
}
#endif

t->sys_sec_stamp = now;
SCMutexUnlock(&thread_store_lock);
thread_v->sys_sec_stamp = now;
}

bool TmThreadsTimeSubsysIsReady(void)
Expand All @@ -2222,7 +2209,7 @@ bool TmThreadsTimeSubsysIsReady(void)
break;
if (t->type != TVT_PPT)
continue;
if (SCTIME_CMP_EQ(t->sys_sec_stamp, nullts)) {
if (SCTIME_CMP_EQ(t->tv->sys_sec_stamp, nullts)) {
ready = false;
break;
}
Expand All @@ -2241,8 +2228,8 @@ void TmThreadsInitThreadsTimestamp(const SCTime_t ts)
break;
if (t->type != TVT_PPT)
continue;
t->pktts = ts;
t->sys_sec_stamp = now;
t->tv->pktts = ts;
t->tv->sys_sec_stamp = now;
}
SCMutexUnlock(&thread_store_lock);
}
Expand All @@ -2263,18 +2250,18 @@ void TmThreadsGetMinimalTimestamp(struct timeval *ts)
/* only packet threads set timestamps based on packets */
if (t->type != TVT_PPT)
continue;
if (SCTIME_CMP_NEQ(t->pktts, nullts)) {
SCTime_t sys_sec_stamp = SCTIME_ADD_SECS(t->sys_sec_stamp, 1);
if (SCTIME_CMP_NEQ(t->tv->pktts, nullts)) {
SCTime_t sys_sec_stamp = SCTIME_ADD_SECS(t->tv->sys_sec_stamp, 1);
/* ignore sleeping threads */
if (SCTIME_CMP_LT(sys_sec_stamp, now))
continue;

if (!set) {
SCTIME_TO_TIMEVAL(&local, t->pktts);
SCTIME_TO_TIMEVAL(&local, t->tv->pktts);
set = true;
} else {
if (SCTIME_CMP_LT(t->pktts, SCTIME_FROM_TIMEVAL(&local))) {
SCTIME_TO_TIMEVAL(&local, t->pktts);
if (SCTIME_CMP_LT(t->tv->pktts, SCTIME_FROM_TIMEVAL(&local))) {
SCTIME_TO_TIMEVAL(&local, t->tv->pktts);
}
}
}
Expand Down Expand Up @@ -2324,3 +2311,11 @@ void TmThreadsInjectFlowById(Flow *f, const int id)
TmThreadsCaptureBreakLoop(tv);
}
}

void TimeSetByThread(ThreadVars *thread_v, SCTime_t tv)
{
if (TimeModeIsLive())
return;

TmThreadsSetThreadTimestamp(thread_v, tv);
}
2 changes: 1 addition & 1 deletion src/tm-threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void TmThreadsUnregisterThread(const int id);
void TmThreadsInjectFlowById(Flow *f, const int id);

void TmThreadsInitThreadsTimestamp(const SCTime_t ts);
void TmThreadsSetThreadTimestamp(const int id, const SCTime_t ts);
void TmThreadsSetThreadTimestamp(ThreadVars *thread_v, const SCTime_t ts);
void TmThreadsGetMinimalTimestamp(struct timeval *ts);
uint16_t TmThreadsGetWorkerThreadMax(void);
bool TmThreadsTimeSubsysIsReady(void);
Expand Down
15 changes: 9 additions & 6 deletions src/util-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ int HashTableRemove(HashTable *ht, void *data, uint16_t datalen)
}

if (ht->array[hash]->next == NULL) {
if (ht->Free != NULL)
ht->Free(ht->array[hash]->data);
SCFree(ht->array[hash]);
ht->array[hash] = NULL;
return 0;
if (ht->Compare(ht->array[hash]->data, ht->array[hash]->size, data, datalen) == 1) {
if (ht->Free != NULL)
ht->Free(ht->array[hash]->data);
SCFree(ht->array[hash]);
ht->array[hash] = NULL;
return 0;
}
return -1;
}

HashTableBucket *hashbucket = ht->array[hash], *prev_hashbucket = NULL;
do {
if (ht->Compare(hashbucket->data,hashbucket->size,data,datalen) == 1) {
if (ht->Compare(hashbucket->data, hashbucket->size, data, datalen) == 1) {
if (prev_hashbucket == NULL) {
/* root bucket */
ht->array[hash] = hashbucket->next;
Expand Down
8 changes: 0 additions & 8 deletions src/util-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ bool TimeModeIsLive(void)
return live_time_tracking;
}

void TimeSetByThread(const int thread_id, SCTime_t tv)
{
if (live_time_tracking)
return;

TmThreadsSetThreadTimestamp(thread_id, tv);
}

#ifdef UNITTESTS
void TimeSet(SCTime_t ts)
{
Expand Down
1 change: 0 additions & 1 deletion src/util-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ static inline SCTime_t SCTimeGetTime(void)
void TimeInit(void);
void TimeDeinit(void);

void TimeSetByThread(const int thread_id, SCTime_t tv);
SCTime_t TimeGet(void);

/** \brief initialize a 'struct timespec' from a 'struct timeval'. */
Expand Down
Loading