1b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Copyright 2006 Google Inc. All Rights Reserved. 2b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 3b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Licensed under the Apache License, Version 2.0 (the "License"); 4b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// you may not use this file except in compliance with the License. 5b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// You may obtain a copy of the License at 6b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 7b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// http://www.apache.org/licenses/LICENSE-2.0 8b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 9b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Unless required by applicable law or agreed to in writing, software 10b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// distributed under the License is distributed on an "AS IS" BASIS, 11b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// See the License for the specific language governing permissions and 13b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// limitations under the License. 14b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 15b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// queue.h : simple queue api 16b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 17b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// This is an interface to a simple thread safe queue, 18b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// used to hold data blocks and patterns. 19b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// The order in which the blocks are returned is random. 20b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 21b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#ifndef STRESSAPPTEST_QUEUE_H_ // NOLINT 22b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#define STRESSAPPTEST_QUEUE_H_ 23b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 24b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include <sys/types.h> 25b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include <pthread.h> 26b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 27b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// This file must work with autoconf on its public version, 28b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// so these includes are correct. 29b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include "sattypes.h" // NOLINT 30b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include "pattern.h" // NOLINT 31b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 32b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Tag indicating no preference. 33b0114cb9f332db144f65291211ae65f7f0e814e6Scott Andersonstatic const int kDontCareTag = -1; 34b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Tag indicating no preference. 35b0114cb9f332db144f65291211ae65f7f0e814e6Scott Andersonstatic const int kInvalidTag = 0xf001; 36b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 37b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 38b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// This describes a block of memory, and the expected fill pattern. 39b0114cb9f332db144f65291211ae65f7f0e814e6Scott Andersonstruct page_entry { 40b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson uint64 offset; 41b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson void *addr; 42b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson uint64 paddr; 43b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson class Pattern *pattern; 44b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int32 tag; // These are tags for use in NUMA affinity or other uses. 45b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson uint32 touch; // Counter of the number of reads from this page. 46b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson uint64 ts; // Timestamp of the last read from this page. 47b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson class Pattern *lastpattern; // Expected Pattern at last read. 48b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson}; 49b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 50b0114cb9f332db144f65291211ae65f7f0e814e6Scott Andersonstatic inline void init_pe(struct page_entry *pe) { 51b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pe->offset = 0; 52b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pe->addr = NULL; 53b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pe->pattern = NULL; 54b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pe->tag = kInvalidTag; 55b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pe->touch = 0; 56b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pe->ts = 0; 57b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pe->lastpattern = NULL; 58b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson} 59b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 60b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// This is a threadsafe randomized queue of pages for 61b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// worker threads to use. 62b0114cb9f332db144f65291211ae65f7f0e814e6Scott Andersonclass PageEntryQueue { 63b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson public: 64b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson explicit PageEntryQueue(uint64 queuesize); 65b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson ~PageEntryQueue(); 66b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 67b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson // Push a page onto the list. 68b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int Push(struct page_entry *pe); 69b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson // Pop a random page off of the list. 70b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int PopRandom(struct page_entry *pe); 71b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 72b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson private: 73b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson struct page_entry *pages_; // Where the pages are held. 74b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int64 nextin_; 75b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int64 nextout_; 76b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int64 q_size_; // Size of the queue. 77b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int64 pushed_; // Number of pages pushed, total. 78b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson int64 popped_; // Number of pages popped, total. 79b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson pthread_mutex_t q_mutex_; 80b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 81b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson DISALLOW_COPY_AND_ASSIGN(PageEntryQueue); 82b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson}; 83b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 84b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson 85b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#endif // MILES_TESTS_SAT_QUEUE_H_ NOLINT 86