/* LUA: __gc and buffer:close() Releases the buffer resources */ static int buffer_event_gc(lua_State* L) { le_bufferevent* ev = buffer_event_get(L, 1); if(ev->ev) { le_buffer *read, *write; bufferevent_free(ev->ev); ev->ev = NULL; /* Also clear out the associated input/output event_buffers * since they would have already been freed.. */ lua_getfenv(L, 1); lua_rawgeti(L, -1, READ_BUFFER_LOCATION); lua_rawgeti(L, -2, WRITE_BUFFER_LOCATION); read = event_buffer_check(L, -2); write = event_buffer_check(L, -1); /* Erase Lua's link to the buffers */ lua_pushnil(L); /* LS: ..., fenv, readBuf, writeBuf, nil */ lua_rawseti(L, -4, READ_BUFFER_LOCATION); lua_pushnil(L); lua_rawseti(L, -4, WRITE_BUFFER_LOCATION); /* Erase their knowledge of the buffer so that the GC won't try to double-free */ read->buffer = NULL; write->buffer = NULL; } return 0; }
static irqreturn_t armv7_pmnc_interrupt(int irq, void *arg) { unsigned int cnt, cpu = smp_processor_id(), buftype = EVENT_BUF; struct pt_regs * const regs = get_irq_regs(); u32 flags; // Stop irq generation armv7_pmnc_write(armv7_pmnc_read() & ~PMNC_E); // Get and reset overflow status flags flags = armv7_pmnc_reset_interrupt(); // Counters header gator_buffer_write_packed_int(cpu, buftype, MESSAGE_COUNTERS); // type gator_buffer_write_packed_int64(cpu, buftype, gator_get_time()); // time // Cycle counter if (flags & (1 << 31)) { int value = armv7_ccnt_read(pmnc_count[CCNT]); // overrun gator_buffer_write_packed_int(cpu, buftype, 2); // length gator_buffer_write_packed_int(cpu, buftype, pmnc_key[CCNT]); // key gator_buffer_write_packed_int(cpu, buftype, value); // value } // PMNC counters for (cnt = CNT0; cnt < CNTMAX; cnt++) { if (flags & (1 << (cnt - CNT0))) { int value = armv7_cntn_read(cnt, pmnc_count[cnt]); // overrun gator_buffer_write_packed_int(cpu, buftype, 2); // length gator_buffer_write_packed_int(cpu, buftype, pmnc_key[cnt]); // key gator_buffer_write_packed_int(cpu, buftype, value); // value } } // End Counters, length of zero gator_buffer_write_packed_int(cpu, buftype, 0); // Output backtrace gator_add_sample(cpu, buftype, regs); // Check and commit; commit is set to occur once buffer is 3/4 full event_buffer_check(cpu); // Allow irq generation armv7_pmnc_write(armv7_pmnc_read() | PMNC_E); return IRQ_HANDLED; }