167207b96SArnd Bergmann /*
267207b96SArnd Bergmann  * SPU file system
367207b96SArnd Bergmann  *
467207b96SArnd Bergmann  * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
567207b96SArnd Bergmann  *
667207b96SArnd Bergmann  * Author: Arnd Bergmann <arndb@de.ibm.com>
767207b96SArnd Bergmann  *
867207b96SArnd Bergmann  * This program is free software; you can redistribute it and/or modify
967207b96SArnd Bergmann  * it under the terms of the GNU General Public License as published by
1067207b96SArnd Bergmann  * the Free Software Foundation; either version 2, or (at your option)
1167207b96SArnd Bergmann  * any later version.
1267207b96SArnd Bergmann  *
1367207b96SArnd Bergmann  * This program is distributed in the hope that it will be useful,
1467207b96SArnd Bergmann  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1567207b96SArnd Bergmann  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1667207b96SArnd Bergmann  * GNU General Public License for more details.
1767207b96SArnd Bergmann  *
1867207b96SArnd Bergmann  * You should have received a copy of the GNU General Public License
1967207b96SArnd Bergmann  * along with this program; if not, write to the Free Software
2067207b96SArnd Bergmann  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2167207b96SArnd Bergmann  */
2267207b96SArnd Bergmann #ifndef SPUFS_H
2367207b96SArnd Bergmann #define SPUFS_H
2467207b96SArnd Bergmann 
2567207b96SArnd Bergmann #include <linux/kref.h>
26650f8b02SChristoph Hellwig #include <linux/mutex.h>
2767207b96SArnd Bergmann #include <linux/spinlock.h>
2867207b96SArnd Bergmann #include <linux/fs.h>
29ea1ae594SChristoph Hellwig #include <linux/cpumask.h>
3067207b96SArnd Bergmann 
3167207b96SArnd Bergmann #include <asm/spu.h>
325473af04SMark Nutter #include <asm/spu_csa.h>
33b9e3bd77SDwayne Grant McConnell #include <asm/spu_info.h>
3467207b96SArnd Bergmann 
3567207b96SArnd Bergmann /* The magic number for our file system */
3667207b96SArnd Bergmann enum {
3767207b96SArnd Bergmann 	SPUFS_MAGIC = 0x23c9b64e,
3867207b96SArnd Bergmann };
3967207b96SArnd Bergmann 
408b3d6663SArnd Bergmann struct spu_context_ops;
416263203eSArnd Bergmann struct spu_gang;
426263203eSArnd Bergmann 
4336aaccc1SBob Nelson /* ctx->sched_flags */
4436aaccc1SBob Nelson enum {
4536aaccc1SBob Nelson 	SPU_SCHED_NOTIFY_ACTIVE,
46b2c863bdSChristoph Hellwig 	SPU_SCHED_WAS_ACTIVE,	/* was active upon spu_acquire_saved()  */
4736aaccc1SBob Nelson };
4836aaccc1SBob Nelson 
4967207b96SArnd Bergmann struct spu_context {
5067207b96SArnd Bergmann 	struct spu *spu;		  /* pointer to a physical SPU */
515473af04SMark Nutter 	struct spu_state csa;		  /* SPU context save area. */
5267207b96SArnd Bergmann 	spinlock_t mmio_lock;		  /* protects mmio access */
536df10a82SMark Nutter 	struct address_space *local_store; /* local store mapping.  */
546df10a82SMark Nutter 	struct address_space *mfc;	   /* 'mfc' area mappings. */
556df10a82SMark Nutter 	struct address_space *cntl;	   /* 'control' area mappings. */
566df10a82SMark Nutter 	struct address_space *signal1;	   /* 'signal1' area mappings. */
576df10a82SMark Nutter 	struct address_space *signal2;	   /* 'signal2' area mappings. */
5817e0e270SBenjamin Herrenschmidt 	struct address_space *mss;	   /* 'mss' area mappings. */
5917e0e270SBenjamin Herrenschmidt 	struct address_space *psmap;	   /* 'psmap' area mappings. */
6047d3a5faSChristoph Hellwig 	struct mutex mapping_lock;
6186767277SArnd Bergmann 	u64 object_id;		   /* user space pointer for oprofile */
628b3d6663SArnd Bergmann 
638b3d6663SArnd Bergmann 	enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
64650f8b02SChristoph Hellwig 	struct mutex state_mutex;
65e45d48a3SChristoph Hellwig 	struct mutex run_mutex;
668b3d6663SArnd Bergmann 
678b3d6663SArnd Bergmann 	struct mm_struct *owner;
6867207b96SArnd Bergmann 
6967207b96SArnd Bergmann 	struct kref kref;
708b3d6663SArnd Bergmann 	wait_queue_head_t ibox_wq;
718b3d6663SArnd Bergmann 	wait_queue_head_t wbox_wq;
725110459fSArnd Bergmann 	wait_queue_head_t stop_wq;
73a33a7d73SArnd Bergmann 	wait_queue_head_t mfc_wq;
748b3d6663SArnd Bergmann 	struct fasync_struct *ibox_fasync;
758b3d6663SArnd Bergmann 	struct fasync_struct *wbox_fasync;
76a33a7d73SArnd Bergmann 	struct fasync_struct *mfc_fasync;
77a33a7d73SArnd Bergmann 	u32 tagwait;
788b3d6663SArnd Bergmann 	struct spu_context_ops *ops;
792a911f0bSArnd Bergmann 	struct work_struct reap_work;
809add11daSArnd Bergmann 	unsigned long flags;
819add11daSArnd Bergmann 	unsigned long event_return;
826263203eSArnd Bergmann 
836263203eSArnd Bergmann 	struct list_head gang_list;
846263203eSArnd Bergmann 	struct spu_gang *gang;
851474855dSBob Nelson 	struct kref *prof_priv_kref;
861474855dSBob Nelson 	void ( * prof_priv_release) (struct kref *kref);
878389998aSChristoph Hellwig 
88476273adSChristoph Hellwig 	/* owner thread */
89476273adSChristoph Hellwig 	pid_t tid;
90476273adSChristoph Hellwig 
918389998aSChristoph Hellwig 	/* scheduler fields */
92079cdb61SChristoph Hellwig 	struct list_head rq;
9337901802SChristoph Hellwig 	unsigned int time_slice;
9426bec673SChristoph Hellwig 	unsigned long sched_flags;
95ea1ae594SChristoph Hellwig 	cpumask_t cpus_allowed;
962eb1b120SChristoph Hellwig 	int policy;
978389998aSChristoph Hellwig 	int prio;
98e9f8a0b6SChristoph Hellwig 
99e9f8a0b6SChristoph Hellwig 	/* statistics */
100e9f8a0b6SChristoph Hellwig 	struct {
101e9f8a0b6SChristoph Hellwig 		/* updates protected by ctx->state_mutex */
10227ec41d3SAndre Detsch 		enum spu_utilization_state util_state;
10327ec41d3SAndre Detsch 		unsigned long long tstamp;	/* time of last state switch */
10427ec41d3SAndre Detsch 		unsigned long long times[SPU_UTIL_MAX];
105e9f8a0b6SChristoph Hellwig 		unsigned long long vol_ctx_switch;
106e9f8a0b6SChristoph Hellwig 		unsigned long long invol_ctx_switch;
107e9f8a0b6SChristoph Hellwig 		unsigned long long min_flt;
108e9f8a0b6SChristoph Hellwig 		unsigned long long maj_flt;
109e9f8a0b6SChristoph Hellwig 		unsigned long long hash_flt;
110e9f8a0b6SChristoph Hellwig 		unsigned long long slb_flt;
111e9f8a0b6SChristoph Hellwig 		unsigned long long slb_flt_base; /* # at last ctx switch */
112e9f8a0b6SChristoph Hellwig 		unsigned long long class2_intr;
113e9f8a0b6SChristoph Hellwig 		unsigned long long class2_intr_base; /* # at last ctx switch */
114e9f8a0b6SChristoph Hellwig 		unsigned long long libassist;
115e9f8a0b6SChristoph Hellwig 	} stats;
1168e68e2f2SArnd Bergmann 
1178e68e2f2SArnd Bergmann 	struct list_head aff_list;
1188e68e2f2SArnd Bergmann 	int aff_head;
119c5fc8d2aSArnd Bergmann 	int aff_offset;
1206263203eSArnd Bergmann };
1216263203eSArnd Bergmann 
1226263203eSArnd Bergmann struct spu_gang {
1236263203eSArnd Bergmann 	struct list_head list;
1246263203eSArnd Bergmann 	struct mutex mutex;
1256263203eSArnd Bergmann 	struct kref kref;
1266263203eSArnd Bergmann 	int contexts;
1278e68e2f2SArnd Bergmann 
1288e68e2f2SArnd Bergmann 	struct spu_context *aff_ref_ctx;
1298e68e2f2SArnd Bergmann 	struct list_head aff_list_head;
1308e68e2f2SArnd Bergmann 	struct mutex aff_mutex;
1318e68e2f2SArnd Bergmann 	int aff_flags;
132c5fc8d2aSArnd Bergmann 	struct spu *aff_ref_spu;
133c5fc8d2aSArnd Bergmann 	atomic_t aff_sched_count;
13467207b96SArnd Bergmann };
13567207b96SArnd Bergmann 
1368e68e2f2SArnd Bergmann /* Flag bits for spu_gang aff_flags */
1378e68e2f2SArnd Bergmann #define AFF_OFFSETS_SET		1
1388e68e2f2SArnd Bergmann #define AFF_MERGED		2
1398e68e2f2SArnd Bergmann 
140a33a7d73SArnd Bergmann struct mfc_dma_command {
141a33a7d73SArnd Bergmann 	int32_t pad;	/* reserved */
142a33a7d73SArnd Bergmann 	uint32_t lsa;	/* local storage address */
143a33a7d73SArnd Bergmann 	uint64_t ea;	/* effective address */
144a33a7d73SArnd Bergmann 	uint16_t size;	/* transfer size */
145a33a7d73SArnd Bergmann 	uint16_t tag;	/* command tag */
146a33a7d73SArnd Bergmann 	uint16_t class;	/* class ID */
147a33a7d73SArnd Bergmann 	uint16_t cmd;	/* command opcode */
148a33a7d73SArnd Bergmann };
149a33a7d73SArnd Bergmann 
150a33a7d73SArnd Bergmann 
1518b3d6663SArnd Bergmann /* SPU context query/set operations. */
1528b3d6663SArnd Bergmann struct spu_context_ops {
1538b3d6663SArnd Bergmann 	int (*mbox_read) (struct spu_context * ctx, u32 * data);
1548b3d6663SArnd Bergmann 	 u32(*mbox_stat_read) (struct spu_context * ctx);
1553a843d7cSArnd Bergmann 	unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
1563a843d7cSArnd Bergmann 					unsigned int events);
1578b3d6663SArnd Bergmann 	int (*ibox_read) (struct spu_context * ctx, u32 * data);
1588b3d6663SArnd Bergmann 	int (*wbox_write) (struct spu_context * ctx, u32 data);
1598b3d6663SArnd Bergmann 	 u32(*signal1_read) (struct spu_context * ctx);
1608b3d6663SArnd Bergmann 	void (*signal1_write) (struct spu_context * ctx, u32 data);
1618b3d6663SArnd Bergmann 	 u32(*signal2_read) (struct spu_context * ctx);
1628b3d6663SArnd Bergmann 	void (*signal2_write) (struct spu_context * ctx, u32 data);
1638b3d6663SArnd Bergmann 	void (*signal1_type_set) (struct spu_context * ctx, u64 val);
1648b3d6663SArnd Bergmann 	 u64(*signal1_type_get) (struct spu_context * ctx);
1658b3d6663SArnd Bergmann 	void (*signal2_type_set) (struct spu_context * ctx, u64 val);
1668b3d6663SArnd Bergmann 	 u64(*signal2_type_get) (struct spu_context * ctx);
1678b3d6663SArnd Bergmann 	 u32(*npc_read) (struct spu_context * ctx);
1688b3d6663SArnd Bergmann 	void (*npc_write) (struct spu_context * ctx, u32 data);
1698b3d6663SArnd Bergmann 	 u32(*status_read) (struct spu_context * ctx);
1708b3d6663SArnd Bergmann 	char*(*get_ls) (struct spu_context * ctx);
1713960c260SJeremy Kerr 	 u32 (*runcntl_read) (struct spu_context * ctx);
1725110459fSArnd Bergmann 	void (*runcntl_write) (struct spu_context * ctx, u32 data);
173c25620d7SMasato Noguchi 	void (*runcntl_stop) (struct spu_context * ctx);
174ee2d7340SArnd Bergmann 	void (*master_start) (struct spu_context * ctx);
175ee2d7340SArnd Bergmann 	void (*master_stop) (struct spu_context * ctx);
176a33a7d73SArnd Bergmann 	int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
177a33a7d73SArnd Bergmann 	u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
178a33a7d73SArnd Bergmann 	u32 (*get_mfc_free_elements)(struct spu_context *ctx);
179a33a7d73SArnd Bergmann 	int (*send_mfc_command)(struct spu_context * ctx,
180a33a7d73SArnd Bergmann 				struct mfc_dma_command * cmd);
181b9e3bd77SDwayne Grant McConnell 	void (*dma_info_read) (struct spu_context * ctx,
182b9e3bd77SDwayne Grant McConnell 			       struct spu_dma_info * info);
183b9e3bd77SDwayne Grant McConnell 	void (*proxydma_info_read) (struct spu_context * ctx,
184b9e3bd77SDwayne Grant McConnell 				    struct spu_proxydma_info * info);
18557dace23SArnd Bergmann 	void (*restart_dma)(struct spu_context *ctx);
1868b3d6663SArnd Bergmann };
1878b3d6663SArnd Bergmann 
1888b3d6663SArnd Bergmann extern struct spu_context_ops spu_hw_ops;
1898b3d6663SArnd Bergmann extern struct spu_context_ops spu_backing_ops;
1908b3d6663SArnd Bergmann 
19167207b96SArnd Bergmann struct spufs_inode_info {
19267207b96SArnd Bergmann 	struct spu_context *i_ctx;
1936263203eSArnd Bergmann 	struct spu_gang *i_gang;
19467207b96SArnd Bergmann 	struct inode vfs_inode;
19543c2bbd9SChristoph Hellwig 	int i_openers;
19667207b96SArnd Bergmann };
19767207b96SArnd Bergmann #define SPUFS_I(inode) \
19867207b96SArnd Bergmann 	container_of(inode, struct spufs_inode_info, vfs_inode)
19967207b96SArnd Bergmann 
20067207b96SArnd Bergmann extern struct tree_descr spufs_dir_contents[];
2015737edd1SMark Nutter extern struct tree_descr spufs_dir_nosched_contents[];
20267207b96SArnd Bergmann 
20367207b96SArnd Bergmann /* system call implementation */
20498f06978SJeremy Kerr extern struct spufs_calls spufs_calls;
20550af32a9SJeremy Kerr long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *status);
2068e68e2f2SArnd Bergmann long spufs_create(struct nameidata *nd, unsigned int flags,
2078e68e2f2SArnd Bergmann 			mode_t mode, struct file *filp);
20848cad41fSMichael Ellerman /* ELF coredump callbacks for writing SPU ELF notes */
20948cad41fSMichael Ellerman extern int spufs_coredump_extra_notes_size(void);
2107af1443aSMichael Ellerman extern int spufs_coredump_extra_notes_write(struct file *file, loff_t *foffset);
21148cad41fSMichael Ellerman 
2129c2e08c5SArjan van de Ven extern const struct file_operations spufs_context_fops;
21367207b96SArnd Bergmann 
2146263203eSArnd Bergmann /* gang management */
2156263203eSArnd Bergmann struct spu_gang *alloc_spu_gang(void);
2166263203eSArnd Bergmann struct spu_gang *get_spu_gang(struct spu_gang *gang);
2176263203eSArnd Bergmann int put_spu_gang(struct spu_gang *gang);
2186263203eSArnd Bergmann void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);
2196263203eSArnd Bergmann void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
2206263203eSArnd Bergmann 
22157dace23SArnd Bergmann /* fault handling */
22257dace23SArnd Bergmann int spufs_handle_class1(struct spu_context *ctx);
22357dace23SArnd Bergmann 
224c5fc8d2aSArnd Bergmann /* affinity */
225c5fc8d2aSArnd Bergmann struct spu *affinity_check(struct spu_context *ctx);
226c5fc8d2aSArnd Bergmann 
22767207b96SArnd Bergmann /* context management */
22865de66f0SChristoph Hellwig extern atomic_t nr_spu_contexts;
2296a0641e5SChristoph Hellwig static inline void spu_acquire(struct spu_context *ctx)
2306a0641e5SChristoph Hellwig {
2316a0641e5SChristoph Hellwig 	mutex_lock(&ctx->state_mutex);
2326a0641e5SChristoph Hellwig }
2336a0641e5SChristoph Hellwig 
2346a0641e5SChristoph Hellwig static inline void spu_release(struct spu_context *ctx)
2356a0641e5SChristoph Hellwig {
2366a0641e5SChristoph Hellwig 	mutex_unlock(&ctx->state_mutex);
2376a0641e5SChristoph Hellwig }
2386a0641e5SChristoph Hellwig 
2396263203eSArnd Bergmann struct spu_context * alloc_spu_context(struct spu_gang *gang);
24067207b96SArnd Bergmann void destroy_spu_context(struct kref *kref);
24167207b96SArnd Bergmann struct spu_context * get_spu_context(struct spu_context *ctx);
24267207b96SArnd Bergmann int put_spu_context(struct spu_context *ctx);
2435110459fSArnd Bergmann void spu_unmap_mappings(struct spu_context *ctx);
24467207b96SArnd Bergmann 
2458b3d6663SArnd Bergmann void spu_forget(struct spu_context *ctx);
24626bec673SChristoph Hellwig int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags);
24767207b96SArnd Bergmann void spu_acquire_saved(struct spu_context *ctx);
24827b1ea09SChristoph Hellwig void spu_release_saved(struct spu_context *ctx);
24950b520d4SChristoph Hellwig 
25026bec673SChristoph Hellwig int spu_activate(struct spu_context *ctx, unsigned long flags);
2518b3d6663SArnd Bergmann void spu_deactivate(struct spu_context *ctx);
2528b3d6663SArnd Bergmann void spu_yield(struct spu_context *ctx);
25336aaccc1SBob Nelson void spu_switch_notify(struct spu *spu, struct spu_context *ctx);
254fe443ef2SChristoph Hellwig void spu_set_timeslice(struct spu_context *ctx);
2552cf2b3b4SChristoph Hellwig void spu_update_sched_info(struct spu_context *ctx);
2562cf2b3b4SChristoph Hellwig void __spu_update_sched_info(struct spu_context *ctx);
2578b3d6663SArnd Bergmann int __init spu_sched_init(void);
258d1450317SSebastian Siewior void spu_sched_exit(void);
2598b3d6663SArnd Bergmann 
260c6730ed4SJeremy Kerr extern char *isolated_loader;
261c6730ed4SJeremy Kerr 
262ce8ab854SArnd Bergmann /*
263ce8ab854SArnd Bergmann  * spufs_wait
264ce8ab854SArnd Bergmann  *	Same as wait_event_interruptible(), except that here
265ce8ab854SArnd Bergmann  *	we need to call spu_release(ctx) before sleeping, and
266ce8ab854SArnd Bergmann  *	then spu_acquire(ctx) when awoken.
267ce8ab854SArnd Bergmann  */
268ce8ab854SArnd Bergmann 
269ce8ab854SArnd Bergmann #define spufs_wait(wq, condition)					\
270ce8ab854SArnd Bergmann ({									\
271ce8ab854SArnd Bergmann 	int __ret = 0;							\
272ce8ab854SArnd Bergmann 	DEFINE_WAIT(__wait);						\
273ce8ab854SArnd Bergmann 	for (;;) {							\
274ce8ab854SArnd Bergmann 		prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE);	\
275ce8ab854SArnd Bergmann 		if (condition)						\
276ce8ab854SArnd Bergmann 			break;						\
277d3764397SJeremy Kerr 		if (signal_pending(current)) {				\
278d3764397SJeremy Kerr 			__ret = -ERESTARTSYS;				\
279d3764397SJeremy Kerr 			break;						\
280d3764397SJeremy Kerr 		}							\
281ce8ab854SArnd Bergmann 		spu_release(ctx);					\
282ce8ab854SArnd Bergmann 		schedule();						\
283ce8ab854SArnd Bergmann 		spu_acquire(ctx);					\
284ce8ab854SArnd Bergmann 	}								\
285ce8ab854SArnd Bergmann 	finish_wait(&(wq), &__wait);					\
286ce8ab854SArnd Bergmann 	__ret;								\
287ce8ab854SArnd Bergmann })
288ce8ab854SArnd Bergmann 
2898b3d6663SArnd Bergmann size_t spu_wbox_write(struct spu_context *ctx, u32 data);
2908b3d6663SArnd Bergmann size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
2918b3d6663SArnd Bergmann 
2928b3d6663SArnd Bergmann /* irq callback funcs. */
2938b3d6663SArnd Bergmann void spufs_ibox_callback(struct spu *spu);
2948b3d6663SArnd Bergmann void spufs_wbox_callback(struct spu *spu);
2955110459fSArnd Bergmann void spufs_stop_callback(struct spu *spu);
296a33a7d73SArnd Bergmann void spufs_mfc_callback(struct spu *spu);
2979add11daSArnd Bergmann void spufs_dma_callback(struct spu *spu, int type);
2988b3d6663SArnd Bergmann 
299bf1ab978SDwayne Grant McConnell extern struct spu_coredump_calls spufs_coredump_calls;
300bf1ab978SDwayne Grant McConnell struct spufs_coredump_reader {
301bf1ab978SDwayne Grant McConnell 	char *name;
302bf1ab978SDwayne Grant McConnell 	ssize_t (*read)(struct spu_context *ctx,
303bf1ab978SDwayne Grant McConnell 			char __user *buffer, size_t size, loff_t *pos);
30474de08bcSMichael Ellerman 	u64 (*get)(struct spu_context *ctx);
305bf1ab978SDwayne Grant McConnell 	size_t size;
306bf1ab978SDwayne Grant McConnell };
307bf1ab978SDwayne Grant McConnell extern struct spufs_coredump_reader spufs_coredump_read[];
308bf1ab978SDwayne Grant McConnell extern int spufs_coredump_num_notes;
309bf1ab978SDwayne Grant McConnell 
310e9f8a0b6SChristoph Hellwig /*
311e9f8a0b6SChristoph Hellwig  * This function is a little bit too large for an inline, but
312e9f8a0b6SChristoph Hellwig  * as fault.c is built into the kernel we can't move it out of
313e9f8a0b6SChristoph Hellwig  * line.
314e9f8a0b6SChristoph Hellwig  */
315e9f8a0b6SChristoph Hellwig static inline void spuctx_switch_state(struct spu_context *ctx,
31627ec41d3SAndre Detsch 		enum spu_utilization_state new_state)
317e9f8a0b6SChristoph Hellwig {
31827ec41d3SAndre Detsch 	unsigned long long curtime;
31927ec41d3SAndre Detsch 	signed long long delta;
32027ec41d3SAndre Detsch 	struct timespec ts;
32127ec41d3SAndre Detsch 	struct spu *spu;
32227ec41d3SAndre Detsch 	enum spu_utilization_state old_state;
32327ec41d3SAndre Detsch 
32427ec41d3SAndre Detsch 	ktime_get_ts(&ts);
32527ec41d3SAndre Detsch 	curtime = timespec_to_ns(&ts);
32627ec41d3SAndre Detsch 	delta = curtime - ctx->stats.tstamp;
32727ec41d3SAndre Detsch 
328e9f8a0b6SChristoph Hellwig 	WARN_ON(!mutex_is_locked(&ctx->state_mutex));
32927ec41d3SAndre Detsch 	WARN_ON(delta < 0);
330e9f8a0b6SChristoph Hellwig 
33127ec41d3SAndre Detsch 	spu = ctx->spu;
33227ec41d3SAndre Detsch 	old_state = ctx->stats.util_state;
33327ec41d3SAndre Detsch 	ctx->stats.util_state = new_state;
334e9f8a0b6SChristoph Hellwig 	ctx->stats.tstamp = curtime;
335e9f8a0b6SChristoph Hellwig 
33627ec41d3SAndre Detsch 	/*
33727ec41d3SAndre Detsch 	 * Update the physical SPU utilization statistics.
33827ec41d3SAndre Detsch 	 */
33927ec41d3SAndre Detsch 	if (spu) {
34027ec41d3SAndre Detsch 		ctx->stats.times[old_state] += delta;
34127ec41d3SAndre Detsch 		spu->stats.times[old_state] += delta;
34227ec41d3SAndre Detsch 		spu->stats.util_state = new_state;
343fe2f896dSChristoph Hellwig 		spu->stats.tstamp = curtime;
344fe2f896dSChristoph Hellwig 	}
345fe2f896dSChristoph Hellwig }
346fe2f896dSChristoph Hellwig 
34767207b96SArnd Bergmann #endif
348