Exemple #1
0
func TestSpc1Init(t *testing.T) {

	// initialize
	var cache *cache.CacheMap
	usedirectio := false
	blocksize := 4 * KB
	s := NewSpcInfo(cache, usedirectio, blocksize)

	// Set fake len
	s.asus[ASU1].len = 5500
	s.asus[ASU2].len = 4500

	// Set asu3 to a value that is too small
	s.asus[ASU3].len = 1

	bsu := 50
	contexts := 1
	err := s.Spc1Init(bsu, contexts)

	// It should not accept a value of asu3
	// because it is too small
	tests.Assert(t, err != nil)

	// Set fake len
	s.asus[ASU1].len = 5500
	s.asus[ASU2].len = 4500
	s.asus[ASU3].len = 1000
	err = s.Spc1Init(bsu, contexts)

	// Now it should succeed
	tests.Assert(t, err == nil)

	// Check that the sizes where adjusted
	tests.Assert(t, s.asus[ASU1].len == 4500)
	tests.Assert(t, s.asus[ASU2].len == 4500)
	tests.Assert(t, s.asus[ASU3].len == 1000)

	// Check spc1 was initialized
	io := spc1.NewSpc1Io(1)
	err = io.Generate()
	tests.Assert(t, err == nil)
}
Exemple #2
0
// Use as a goroutine to start the io workload
// Create one of these per context set on Spc1Init()
func (s *SpcInfo) Context(wg *sync.WaitGroup,
	iotime chan<- *IoStats,
	quit <-chan struct{},
	runlen, context int) {

	defer wg.Done()

	// Spc generator specifies that each context have
	// 8 io streams.  Spc generator will specify which
	// io stream to use.
	streams := 8
	iostreams := make([]chan *IoStats, streams)

	var iostreamwg sync.WaitGroup
	for stream := 0; stream < streams; stream++ {

		// Allow for queued requests
		iostreams[stream] = make(chan *IoStats, 64)

		// Create 32 io contexts per stream
		for i := 0; i < 32; i++ {
			iostreamwg.Add(1)
			go s.sendio(&iostreamwg, iostreams[stream], iotime)
		}
	}

	start := time.Now()
	lastiotime := start
	stop := time.After(time.Second * time.Duration(runlen))
	ioloop := true
	for ioloop {
		select {
		case <-quit:
			ioloop = false
		case <-stop:
			ioloop = false
		default:
			// Get the next io
			io := spc1.NewSpc1Io(context)

			err := io.Generate()
			godbc.Check(err == nil)
			godbc.Invariant(io)

			// Check how much time we should wait
			sleep_time := start.Add(io.When).Sub(lastiotime)
			if sleep_time > 0 {
				time.Sleep(sleep_time)
			}

			// Send io to io stream
			iostreams[io.Stream] <- &IoStats{
				Io:    io,
				Start: time.Now(),
			}

			lastiotime = time.Now()

		}
	}

	// close the streams for this context
	for stream := 0; stream < streams; stream++ {
		close(iostreams[stream])
	}
	iostreamwg.Wait()
}