Skip to content
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
9 changes: 9 additions & 0 deletions iocore/eventsystem/I_Continuation.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "ts/ink_platform.h"
#include "ts/List.h"
#include "I_Lock.h"
#include "ts/ContFlags.h"

class Continuation;
class ContinuationQueue;
Expand Down Expand Up @@ -127,6 +128,12 @@ class Continuation : private force_VFPT_to_top
*/
LINK(Continuation, link);

/**
Contains values for debug_override and future flags that
needs to be thread local while this continuation is running
*/
ContFlags control_flags;

/**
Receives the event code and data for an Event.

Expand Down Expand Up @@ -191,6 +198,8 @@ inline Continuation::Continuation(ProxyMutex *amutex)
#endif
mutex(amutex)
{
// Pick up the control flags from the creating thread
this->control_flags.set_flags(get_cont_flags().get_flags());
}

#endif /*_Continuation_h_*/
5 changes: 5 additions & 0 deletions iocore/net/UnixNet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ NetHandler::mainNetEvent(int event, Event *e)
#if defined(USE_EDGE_TRIGGER)
// UnixNetVConnection *
while ((vc = read_ready_list.dequeue())) {
// Initialize the thread-local continuation flags
set_cont_flags(vc->control_flags);
if (vc->closed)
close_UnixNetVConnection(vc, trigger_event->ethread);
else if (vc->read.enabled && vc->read.triggered)
Expand All @@ -526,6 +528,7 @@ NetHandler::mainNetEvent(int event, Event *e)
}
}
while ((vc = write_ready_list.dequeue())) {
set_cont_flags(vc->control_flags);
if (vc->closed)
close_UnixNetVConnection(vc, trigger_event->ethread);
else if (vc->write.enabled && vc->write.triggered)
Expand All @@ -543,6 +546,7 @@ NetHandler::mainNetEvent(int event, Event *e)
}
#else /* !USE_EDGE_TRIGGER */
while ((vc = read_ready_list.dequeue())) {
diags->set_override(vc->control.debug_override);
if (vc->closed)
close_UnixNetVConnection(vc, trigger_event->ethread);
else if (vc->read.enabled && vc->read.triggered)
Expand All @@ -551,6 +555,7 @@ NetHandler::mainNetEvent(int event, Event *e)
vc->ep.modify(-EVENTIO_READ);
}
while ((vc = write_ready_list.dequeue())) {
diags->set_override(vc->control.debug_override);
if (vc->closed)
close_UnixNetVConnection(vc, trigger_event->ethread);
else if (vc->write.enabled && vc->write.triggered)
Expand Down
71 changes: 71 additions & 0 deletions lib/ts/ContFlags.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/** @file

A brief file description

@section license License

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ContFlags.h"

static ink_thread_key init_thread_key();
static inkcoreapi ink_thread_key flags_data_key = init_thread_key();

static ink_thread_key
init_thread_key()
{
ink_thread_key_create(&flags_data_key, NULL);
return flags_data_key;
}


/* Set up a cont_flags entry for this threa */
void
init_cont_flags()
{
ContFlags new_flags;
ink_thread_setspecific(flags_data_key, (void *)new_flags.get_flags());
}

void
set_cont_flags(const ContFlags &flags)
{
ink_thread_setspecific(flags_data_key, (void *)flags.get_flags());
}

void
set_cont_flag(ContFlags::flags flag_bit, bool value)
{
u_int64_t flags = (u_int64_t)ink_thread_getspecific(flags_data_key);
ContFlags new_flags(flags);
new_flags.set_flag(flag_bit, value);
ink_thread_setspecific(flags_data_key, (void *)new_flags.get_flags());
}

ContFlags
get_cont_flags()
{
return ContFlags((u_int64_t)ink_thread_getspecific(flags_data_key));
}

bool
get_cont_flag(ContFlags::flags flag_bit)
{
ContFlags flags((u_int64_t)ink_thread_getspecific(flags_data_key));
return flags.get_flag(flag_bit);
}
93 changes: 93 additions & 0 deletions lib/ts/ContFlags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/** @file

A brief file description

@section license License

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/****************************************************************************

ContFlags.h

Thread local storage for a set of flags that are updated based the continuation
currently running in the thread. These flags are handy if the data is needed
as a "global" in parts of the code where the original net VC is not available.
Storing the flags in the void * of the thread key directly. I assume we are on
at least a 32 bit architecture, so the rawflags size is 32 bits.
****************************************************************************/

#ifndef _CONT_FLAGS_H
#define _CONT_FLAGS_H

#include "ink_thread.h"

class ContFlags
{
public:
enum flags { DEBUG_OVERRIDE = 0, DISABLE_PLUGINS = 1, LAST_FLAG };

ContFlags() : raw_flags(0) {}
ContFlags(u_int32_t in_flags) : raw_flags(in_flags) {}
void
set_flags(u_int32_t new_flags)
{
raw_flags = new_flags;
}
ContFlags &operator=(ContFlags const &other)
{
this->set_flags(other.get_flags());
return *this;
}

u_int32_t
get_flags() const
{
return raw_flags;
}
void
set_flag(enum flags flag_bit, bool value)
{
if (flag_bit >= 0 && flag_bit < LAST_FLAG) {
if (value)
raw_flags |= (1 << flag_bit);
else
raw_flags &= ~(1 << flag_bit);
}
}
bool
get_flag(enum flags flag_bit) const
{
if (flag_bit >= 0 && flag_bit < LAST_FLAG) {
return (raw_flags & (1 << flag_bit)) != 0;
} else {
return false;
}
}

private:
u_int32_t raw_flags;
};

void init_cont_flags();
void set_cont_flags(const ContFlags &flags);
void set_cont_flag(ContFlags::flags flag_bit, bool value);
ContFlags get_cont_flags();
bool get_cont_flag(ContFlags::flags flag_bit);

#endif // _CONT_FLAGS_H
9 changes: 9 additions & 0 deletions lib/ts/Diags.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "ink_mutex.h"
#include "Regex.h"
#include "ink_apidefs.h"
#include "ContFlags.h"
#include "ink_inet.h"
#include "BaseLogFile.h"

#define DIAGS_MAGIC 0x12345678
Expand Down Expand Up @@ -163,6 +165,13 @@ class Diags
// conditional debugging //
///////////////////////////


bool
get_override() const
{
return get_cont_flag(ContFlags::DEBUG_OVERRIDE);
}

bool
on(DiagsTagType mode = DiagsTagType_Debug) const
{
Expand Down
2 changes: 2 additions & 0 deletions lib/ts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ libtsutil_la_SOURCES = \
Bitops.h \
ConsistentHash.cc \
ConsistentHash.h \
ContFlags.cc \
ContFlags.h \
Cryptohash.h \
Diags.cc \
Diags.h \
Expand Down
3 changes: 3 additions & 0 deletions proxy/http/HttpSM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5619,6 +5619,9 @@ HttpSM::attach_server_session(HttpServerSession *s)
hsm_release_assert(s->state == HSS_ACTIVE);
server_session = s;
server_transact_count = server_session->transact_count++;
// Propagate the per client IP debugging
if (ua_session)
s->get_netvc()->control_flags = get_cont_flags();

// Set the mutex so that we have something to update
// stats with
Expand Down