summaryrefslogtreecommitdiff
path: root/gcell/src/lib/runtime/spu/gc_logging.c
blob: 65a5375040ee1406bb5d471d29596fa93c404b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* -*- c++ -*- */
/*
 * Copyright 2008 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <gc_logging.h>
#include <spu_intrinsics.h>
#include <spu_mfcio.h>
#include <gc_spu_args.h>

static gc_eaddr_t     log_base_ea;	// base address of log entries in EA
static uint32_t	      log_idx_mask;	// nentries - 1
static uint32_t	      log_idx;		// current log entry index
static uint32_t	      log_seqno;

static int 	      log_tags;		// two consecutive tags
static int	      tmp_buffer_busy;	// bitmask: buffer busy state
static int	      tmp_buffer_idx;	// 0 or 1
static gc_log_entry_t tmp_buffer[2];

void
_gc_log_init(gc_log_t info)
{
  spu_write_decrementer(~0);

  log_base_ea = info.base;
  log_idx_mask = info.nentries - 1;
  log_idx = 0;
  log_seqno = 0;

  log_tags = mfc_multi_tag_reserve(2);
  tmp_buffer_busy = 0;
  tmp_buffer_idx = 0;

  gc_log_write0(GCL_SS_SYS, 0);
}

void
_gc_log_write(gc_log_entry_t entry)
{
  if (log_base_ea == 0)
    return;

  entry.seqno = log_seqno++;
  entry.timestamp = spu_read_decrementer();

  if (tmp_buffer_busy & (1 << tmp_buffer_idx)){
    mfc_write_tag_mask(1 << (log_tags + tmp_buffer_idx));
    mfc_read_tag_status_all();
  }

  tmp_buffer[tmp_buffer_idx] = entry;	// save local copy

  mfc_put(&tmp_buffer[tmp_buffer_idx],
	  log_base_ea + log_idx * sizeof(entry), sizeof(entry),
	  log_tags + tmp_buffer_idx, 0, 0);

  tmp_buffer_busy |= (1 << tmp_buffer_idx);
  tmp_buffer_idx ^= 0x1;
  log_idx = (log_idx + 1) & log_idx_mask;
}