Navigation


Changeset 454:f1484823cb4a in freeDiameter


Ignore:
Timestamp:
Jul 29, 2010, 4:11:12 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Small hack which might spear some concurrency problems and is quite harmless

Files:
13 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/cnxctx.c

    r423 r454  
    464464{
    465465        CHECK_PARAMS_DO( conn, return 0 );
     466        fd_cpu_flush_cache();
    466467        return conn->cc_status & CC_STATUS_TLS;
    467468}
     
    545546       
    546547        /* Mark the error */
     548        fd_cpu_flush_cache();
    547549        conn->cc_status |= CC_STATUS_ERROR;
    548550       
     
    553555                conn->cc_status |= CC_STATUS_SIGNALED;
    554556        }
    555        
     557        fd_cpu_flush_cache();
    556558        return;
    557559fatal:
     
    581583        /* Handle special case of timeout */
    582584        if ((ret < 0) && (errno == EAGAIN)) {
     585                fd_cpu_flush_cache();
    583586                if (! (conn->cc_status & CC_STATUS_CLOSING))
    584587                        goto again; /* don't care, just ignore */
     
    607610        /* Handle special case of timeout */
    608611        if ((ret < 0) && (errno == EAGAIN)) {
     612                fd_cpu_flush_cache();
    609613                if (! (conn->cc_status & CC_STATUS_CLOSING))
    610614                        goto again; /* don't care, just ignore */
     
    725729       
    726730        do {
     731                fd_cpu_flush_cache();
    727732                CHECK_FCT_DO( fd_sctp_recvmeta(conn->cc_socket, NULL, &buf, &bufsz, &event, &conn->cc_status), goto fatal );
    728733                if (event == FDEVP_CNX_ERROR) {
     
    796801                        switch (ret) {
    797802                                case GNUTLS_E_REHANDSHAKE:
     803                                        fd_cpu_flush_cache();
    798804                                        if (!(conn->cc_status & CC_STATUS_CLOSING))
    799805                                                CHECK_GNUTLS_DO( ret = gnutls_handshake(session),
     
    807813                                case GNUTLS_E_AGAIN:
    808814                                case GNUTLS_E_INTERRUPTED:
     815                                        fd_cpu_flush_cache();
    809816                                        if (!(conn->cc_status & CC_STATUS_CLOSING))
    810817                                                goto again;
     
    840847                        switch (ret) {
    841848                                case GNUTLS_E_REHANDSHAKE:
     849                                        fd_cpu_flush_cache();
    842850                                        if (!(conn->cc_status & CC_STATUS_CLOSING))
    843851                                                CHECK_GNUTLS_DO( ret = gnutls_handshake(session),
     
    851859                                case GNUTLS_E_AGAIN:
    852860                                case GNUTLS_E_INTERRUPTED:
     861                                        fd_cpu_flush_cache();
    853862                                        if (!(conn->cc_status & CC_STATUS_CLOSING))
    854863                                                goto again;
     
    12351244
    12361245        /* Mark the connection as protected from here, so that the gnutls credentials will be freed */
     1246        fd_cpu_flush_cache();
    12371247        conn->cc_status |= CC_STATUS_TLS;
    12381248
     
    13591369        TRACE_ENTRY("%p %p %zd", conn, buf, len);
    13601370        do {
     1371                fd_cpu_flush_cache();
    13611372                if (conn->cc_status & CC_STATUS_TLS) {
    13621373                        CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_tls_para.session, buf + sent, len - sent),  );
     
    13921403                                /* Send the buffer over all other streams */
    13931404                                uint16_t str;
     1405                                fd_cpu_flush_cache();
    13941406                                if (conn->cc_status & CC_STATUS_TLS) {
    13951407                                        for ( str=1; str < conn->cc_sctp_para.pairs; str++) {
     
    14741486        CHECK_PARAMS_DO(conn, return);
    14751487       
     1488        fd_cpu_flush_cache();
    14761489        conn->cc_status |= CC_STATUS_CLOSING;
    14771490       
  • freeDiameter/p_ce.c

    r403 r454  
    613613       
    614614        /* Are we doing an election ? */
     615        fd_cpu_flush_cache();
    615616        if (peer->p_hdr.info.runtime.pir_state == STATE_WAITCNXACK_ELEC) {
    616617                if (election_result(peer)) {
     
    661662       
    662663        /* If the state is not WAITCEA, just discard the message */
     664        fd_cpu_flush_cache();
    663665        if (req || (peer->p_hdr.info.runtime.pir_state != STATE_WAITCEA)) {
    664666                if (*msg) {
     
    922924int fd_p_ce_handle_newCER(struct msg ** msg, struct fd_peer * peer, struct cnxctx ** cnx, int valid)
    923925{
     926        fd_cpu_flush_cache();
    924927        switch (peer->p_hdr.info.runtime.pir_state) {
    925928                case STATE_CLOSED:
  • freeDiameter/p_dp.c

    r403 r454  
    114114        } else {
    115115                /* We received a DPA */
     116                fd_cpu_flush_cache();
    116117                if (peer->p_hdr.info.runtime.pir_state != STATE_CLOSING) {
    117118                        TRACE_DEBUG(INFO, "Ignoring DPA received in state %s", STATE_STR(peer->p_hdr.info.runtime.pir_state));
  • freeDiameter/p_dw.c

    r258 r454  
    123123       
    124124        /* If we are in REOPEN state, increment the counter */
     125        fd_cpu_flush_cache();
    125126        if (peer->p_hdr.info.runtime.pir_state == STATE_REOPEN) {
    126127                peer->p_flags.pf_reopen_cnt += 1;
  • freeDiameter/p_expiry.c

    r78 r454  
    6161                        struct fd_peer * peer = (struct fd_peer *)li;
    6262                       
     63                        fd_cpu_flush_cache();
    6364                        if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE)
    6465                                continue;
  • freeDiameter/p_out.c

    r258 r454  
    143143        CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx)));
    144144       
     145        fd_cpu_flush_cache();
    145146        if (peer && (peer->p_hdr.info.runtime.pir_state == STATE_OPEN)) {
    146147                /* Normal case: just queue for the out thread to pick it up */
  • freeDiameter/p_psm.c

    r403 r454  
    184184        TRACE_ENTRY("%p %d(%s)", peer, new_state, STATE_STR(new_state));
    185185        CHECK_PARAMS( CHECK_PEER(peer) );
     186        fd_cpu_flush_cache();
    186187        old = peer->p_hdr.info.runtime.pir_state;
    187188        if (old == new_state)
     
    194195       
    195196        peer->p_hdr.info.runtime.pir_state = new_state;
     197        fd_cpu_flush_cache();
    196198       
    197199        if (old == STATE_OPEN) {
     
    251253{
    252254        /* Move to CLOSED state: failover messages, stop OUT thread, unlink peer from active list */
     255        fd_cpu_flush_cache();
    253256        if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) {
    254257                CHECK_FCT_DO( fd_psm_change_state(peer, STATE_CLOSED), /* continue */ );
     
    281284        CHECK_PARAMS_DO( CHECK_PEER(peer), return );
    282285        peer->p_hdr.info.runtime.pir_state = STATE_ZOMBIE;
     286        fd_cpu_flush_cache();
    283287        return;
    284288}
     
    306310        /* The state machine starts in CLOSED state */
    307311        peer->p_hdr.info.runtime.pir_state = STATE_CLOSED;
    308        
     312
    309313        /* Wait that the PSM are authorized to start in the daemon */
    310314        CHECK_FCT_DO( fd_psm_waitstart(), goto psm_end );
     
    709713                        peer->p_hdr.info.pi_diamid);
    710714        pthread_cleanup_pop(1); /* set STATE_ZOMBIE */
     715        fd_cpu_flush_cache();
    711716        peer->p_psm = (pthread_t)NULL;
    712717        pthread_detach(pthread_self());
     
    742747        CHECK_PARAMS( CHECK_PEER(peer) );
    743748       
     749        fd_cpu_flush_cache();
    744750        if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) {
    745751                CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, 0, reason) );
  • freeDiameter/peers.c

    r403 r454  
    279279                struct fd_peer * peer = (struct fd_peer *)li;
    280280               
     281                fd_cpu_flush_cache();
    281282                if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) {
    282283                        CHECK_FCT_DO( fd_psm_terminate(peer, "REBOOTING"), /* continue */ );
     
    306307                for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
    307308                        struct fd_peer * peer = (struct fd_peer *)li;
     309                        fd_cpu_flush_cache();
    308310                        if (peer->p_hdr.info.runtime.pir_state == STATE_ZOMBIE) {
    309311                                li = li->prev; /* to avoid breaking the loop */
     
    462464        } else {
    463465                /* Check if the peer is in zombie state */
     466                fd_cpu_flush_cache();
    464467                if (peer->p_hdr.info.runtime.pir_state == STATE_ZOMBIE) {
    465468                        /* Re-activate the peer */
  • freeDiameter/routing_dispatch.c

    r403 r454  
    815815                /* Find the peer corresponding to this name */
    816816                CHECK_FCT( fd_peer_getbyid( qry_src, (void *) &peer ) );
     817                fd_cpu_flush_cache();
    817818                if ((!peer) || (peer->p_hdr.info.runtime.pir_state != STATE_OPEN)) {
    818819                        TRACE_DEBUG(INFO, "Unable to forward answer message to peer '%s', deleted or not in OPEN state.", qry_src);
     
    934935                CHECK_FCT( fd_peer_getbyid( c->diamid, (void *)&peer ) );
    935936
     937                fd_cpu_flush_cache();
    936938                if (peer && (peer->p_hdr.info.runtime.pir_state == STATE_OPEN)) {
    937939                        /* Send to this one */
  • freeDiameter/sctps.c

    r403 r454  
    8787       
    8888        do {
     89                fd_cpu_flush_cache();
    8990                CHECK_FCT_DO( fd_sctp_recvmeta(conn->cc_socket, &strid, &buf, &bufsz, &event, &conn->cc_status), goto fatal );
    9091                switch (event) {
     
    171172        CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } );
    172173       
     174        fd_cpu_flush_cache();
    173175        CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent->cc_socket, ctx->strid, (uint8_t *)data, len, &ctx->parent->cc_status), /* errno is already set */ return -1 );
    174176       
     
    620622        /* End all TLS sessions, in series (not as efficient as paralel, but simpler) */
    621623        for (i = 1; i < conn->cc_sctp_para.pairs; i++) {
     624                fd_cpu_flush_cache();
    622625                if ( ! (conn->cc_status & CC_STATUS_ERROR)) {
    623626                        CHECK_GNUTLS_DO( gnutls_bye(conn->cc_sctps_data.array[i].session, GNUTLS_SHUT_WR), fd_cnx_markerror(conn) );
  • include/freeDiameter/freeDiameter.h

    r447 r454  
    228228        struct {
    229229               
    230                 enum peer_state pir_state;      /* Current state of the peer in the state machine */
     230                enum peer_state pir_state;      /* Current state of the peer in the state machine. fd_cpu_flush_cache() might be useful before reading. */
    231231               
    232232                char *          pir_realm;      /* The received realm in CER/CEA. */
     
    252252        struct fd_list  pi_endpoints;   /* Endpoint(s) of the remote peer (configured, discovered, or advertized). list of struct fd_endpoint. DNS resolved if empty. */
    253253};
     254
    254255
    255256struct peer_hdr {
  • include/freeDiameter/libfreeDiameter.h

    r453 r454  
    569569}
    570570
     571/* Force flushing the cache of a CPU before reading a shared memory area (use only for atomic reads such as int and void*) */
     572extern pthread_mutex_t fd_cpu_mtx_dummy; /* only for the macro bellow, so that we have reasonably fresh pir_state value when needed */
     573#define fd_cpu_flush_cache() {                          \
     574        (void)pthread_mutex_lock(&fd_cpu_mtx_dummy);    \
     575        (void)pthread_mutex_unlock(&fd_cpu_mtx_dummy);  \
     576}
     577
     578
    571579/*************
    572580 Cancelation cleanup handlers for common objects
  • libfreeDiameter/init.c

    r258 r454  
    3636#include "libfD.h"
    3737
     38/* Only for CPU cache flush */
     39pthread_mutex_t fd_cpu_mtx_dummy = PTHREAD_MUTEX_INITIALIZER;
     40
    3841/* Initialize library variables and threads */
    3942int fd_lib_init(int support_signals)
Note: See TracChangeset for help on using the changeset viewer.